你如何张贴在PhoneGap的一种形式? [英] How do you post a form in Phonegap?

查看:111
本文介绍了你如何张贴在PhoneGap的一种形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想出来的PhoneGap和在HTML中具有非常简单的应用程序。

I am trying out Phonegap and have a very simple app in html.

<!DOCTYPE html>
<html>
    <title>&nbsp;</title>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    </head>
    <body>
        <div data-role="page" id="page1">
            <div data-role="header">
                <h1>Trying out Phonegap</h1>
            </div>
            <div data-role="content">
                <h3>Sign in here</h3>
                <form>
                    Username
                    <input type='text' name='username'>
                    Password
                    <input type='text' name='password'>
                    <input type='submit' name='submit' value='Login'>
                </form>
            </div>
        </div>
    </body>
</html>

但我不知道如何处理表单提交。我应该直接发布到外部URL api.myserver.com/signin或者我应​​该使用jQuery来发布领域的API,然后切换到基于响应另一种观点?任何意见或code段将是非常有用的。

But I don't know how to handle the form submission. Should I post directly to an external url api.myserver.com/signin or should I be using JQuery to post the fields to an API and then change to another view based on the response? Any comments or code snippets would be really useful.

推荐答案

您应该使用JavaScript / jQuery来检索的形式输入的数值时提交事件触发,然后使用AJAX的值发送到远程服务器并等待响应。

You should use javascript/jQuery to retrieve the values of the inputs in the form when the submit event fires, then use ajax to send the values to a remote server and wait for a response.

根据不同的反应,你可以继续你喜欢的任何方式;显示对话框,更改网页等。

Depending on the response, you can proceed on whichever way you like; show dialogs, change pages, etc.

这篇关于你如何张贴在PhoneGap的一种形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆