phonegap表单提交到远程服务器 [英] phonegap form submission to remote server

查看:134
本文介绍了phonegap表单提交到远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的问题:
我在index.html中有一个表单,它将有一个文本输入,值将是$ .post到一个php页面,应该处理它,并将返回一个值。我的代码:

Here's my problem: I have a form in index.html, it will have a text input, and the value will be $.post to a php page that should process it and will return a value. My code:

index.html:

index.html:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>

<script>
    function get(){
        $.post('http://xxx/xxx/get.php', {name: form.name.value},
            function(output){
                $('#result').html(output).show();
            });
    }
</script>

</head>
<body>

<div data-role="page" id="header">

<div data-role="header">
<h1>Header</h1>
</div>

<div data-role="content">

<form name="form" id="form">
    <input type="text" name="name"><input type="button" value="Get Output" onClick="get();">
</form>

<p> result here: </p>
<div id="result"></div>

</div>

<div data-role="footer">
<h4>Footer</h4>
</div>

</div>
</body>
</body>
</html>

和get.php

<?php
$name = $_POST['name'];
echo $name;
?>

这是我测试目的的简单编码。从代码中我们可以看出,我们在textfield中输入的任何文本都将在get.php中处理。因为我把echo $ name放在那里,名字应该显示在div id = result in index.html中。我想我得到的代码正确,但它只是没有工作。所以我需要来自专家的帮助...我做错了什么?

This is simple coding for my testing purpose. As we can see from the code, whatever text we input in the textfield will be processed in get.php. Since I put echo $name there, the name SHOULD be shown in div id = result in index.html. I think I got the code right but it just didn't work. So I need help from the experts here... what did I do wrong?

推荐答案

以下几点:


将远程服务器添加到白名单...如果您使用的是黑莓,您必须编辑config.xml文件,如果是ios应用程序,您必须更改项目的plist文件。

1. Add the remote server to the whitelist...if you are using blackberry ou must edit the config.xml file, if is a ios app, you must change the plist file of the project.

EDIT 2011-11-03:在Android中:
确保此行在phonegap应用清单文件中:
< uses-permission android:name =android.permission.INTERNET>

EDIT 2011-11-03: In Android: Make sure this line is in phonegap app manifest file: < uses-permission android:name="android.permission.INTERNET">

2。
尝试将此标题添加到php文件头('Access-Control-Allow-Origin:*');

2. Try adding this header to the php file header('Access-Control-Allow-Origin: *');

03:,此标题必须包含在PHP文件的开头。

EDIT 2011-11-03: this header must be included on the beginning of the PHP file.



  1. $ ').html(output).show();

祝你好运!

这篇关于phonegap表单提交到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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