【发布时间】:2011-11-17 16:47:41
【问题描述】:
我正在 phonegap 中开发一个应用程序,我正在尝试使用 jquery 和 json 将 formdata 从 phonegap 传递到远程服务器并将其保存到 mysql 数据库中。 之前没用过json,真的不知道怎么在服务器上接收解析这些数据。
谁能帮我写一个简单的php脚本来处理这个?
这是我用来发送数据的表单和 jquery:
<form method="post" id="infoForm">
<input type="text" name="first_name" id="first_name" value="" placeholder="First Name" />
<input type="text" name="last_name" id="last_name" value="" placeholder="Last Name" />
<input type="text" name="email" id="email" value="" placeholder="Email" />
<button type="submit">Submit</button>
</form>
$('#infoForm').submit(function() {
var postTo = 'http://siteurl.com';
$.post(postTo,({first_name: $('[name=first_name]').val(), last_name: $('[name=last_name]').val(), email: $('[name=email]').val()}),
function(data) {
alert(data);
if(data != "") {
// do something
} else {
// couldn't connect
}
},'json');
return false;
});
我已经尝试了几个小时没有任何结果。
谢谢!
【问题讨论】: