jQuery的工艺形式 [英] jQuery process form

查看:108
本文介绍了jQuery的工艺形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一个是一个非常简单的问题(我希望),但只是靠在/掌握jQuery的我提前道歉。

This one is a really simple question (I hope), but as just leaning/getting to grips with jQuery I apologize in advance.

如果我有一个表格例如,

If I have a form e.g.

<form id="form">
<input type="text" name="abc" />
<input type="text" name="def"/>
<input type="text" name="ghi"/>
<input type="submit" name="try" id="try" />
</form>

然后通过jQuery像这样把它

And then send it via jQuery like this

$.post("process.php", $("#form").serialize());

我如何访问来处理process.php的信息的数据?即通过一个简单的PHP插入查询(我可以写PHP的!),只是我怎么访问序列化的数据。同样是有办法的所有数据(从3场)送我的变量 - 我认为这是JSON?如果是的话,我怎么再重新处理这些信息时,我调用数据库,以显示它

How do I access the data to process the information on process.php? i.e. via a simple PHP insert query (I can write the PHP!), just how do I access the serialized data. Also is there a way to send all the data (from the 3 fields) as i variable - I think this is JSON?, if so, how do I then reprocess that info when I call the database to display it.

我有一个很好的把握的大多数事情,所以你不必过分简单,只是一些普通的指针会有所帮助。谢谢

I have a good grasp of most things so you don't need to be over simplistic, but just some general pointers would help. Thanks

推荐答案

在process.php的数据已经有反序列化的全局变量$ _POST。

In process.php the data will already be available deserialized in the $_POST superglobal.

JSON是序列化最适合发送从PHP响应返回给JavaScript的另一种形式。

JSON is another form of serialization best suited to send responses from PHP back to javascript.

因此​​,在你的情况,例如,process.php读取$ _ POST,不知怎么处理的结果,那么你可以格式的脚本返回值在数组中,使用的 json_en code()和模具($ json_en coded_variable_here),使其返回到jQuery的。

So in your case, for example, process.php reads $_POST, processes the result somehow and then you could format the scripts return values in an array, use json_encode() and die($json_encoded_variable_here) to return it to jquery.

在jQuery的你可以添加一个回调到您的功能:

In jquery you could add a callback to your function:

$.post("process.php", $("#form").serialize(), function(json){
    // the variable json is the JSON died() by php and can be easily parsed by jquery
}, 'json');

这篇关于jQuery的工艺形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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