ari*_*rik 5 javascript jquery post submission intercept
我有一张表格.此表单通过POST提交给iframe,iframe又处理了请求,并根据结果执行javascript,根据提交的有效性更改父级内容.
现在,我不喜欢这个程序.我希望能够同时提交多个表单,但我只有一个隐藏的iframe.所以我想用AJAX做,为每个表单提交创建一个单独的请求.
但是,我的形式很复杂; 它包括向数组添加变量的复选框,单击的图像以及我需要发送的点击坐标,以及类似复杂的东西 - 这就是为什么我,而不是计算每个输入的值并将其添加到post参数字符串(顺便说一句:我不知道如何以这种方式创建数组),我更愿意将截取的提交内容保存为包含所有这些参数的帖子字符串,然后将此字符串用于AJAX POST请求.
我想在这个函数中做:
$('#myForm').submit(function(event){
// process the submission, e. g. event.getContent().toPostString();
// create the AJAX request and send it and attach listeners (I know how to do this line ;)
return false; // I don't want the form submitted (to the iframe)
});
Run Code Online (Sandbox Code Playgroud)
提前致谢!
不要使用iframe,只需使用jQuery的ajax方法 :(我post()在下面的例子中使用过)
$('#myForm').submit(function(event){
//url //post data
$.post(this.action, $(this).serialize(), function(returnData){
//do something with returnData
})
return false; //do not submit form the normal way
});
Run Code Online (Sandbox Code Playgroud)
这是一个例子:http://jsfiddle.net/maniator/Y6r8E/
在表单中输入内容并提交.
| 归档时间: |
|
| 查看次数: |
5078 次 |
| 最近记录: |