phonegap表单提交到远程服务器

编程入门 行业动态 更新时间:2024-10-27 18:32:31
本文介绍了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="code.jquery/mobile/1.0a3/jquery.mobile-1.0a3.min.css" /> <script type="text/javascript" src="code.jquery/jquery-1.5.min.js"></script> <script type="text/javascript" src="code.jquery/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script> <script> function get(){ $.post('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.

  • $ ').html(output).show();
  • 祝你好运!

    更多推荐

    phonegap表单提交到远程服务器

    本文发布于:2023-10-09 17:56:59,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1476382.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:表单   服务器   phonegap

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!