0

我会简短我有这个功能

$("#JqPostForm").submit(function(e){    
    e.preventDefault();  
    $("#despliegaresultados").empty();
    $("#paginacion").empty();
    $.post("php/prueba.php", $('#JqPostForm').serialize(),

    function(data)
    {
        $.each(data, function(i, item)
        {
            total= item.total;
            datos = item.datos;
        });

        //is doing something here 

    });
}, "json");

用这个 html

<html>
.....
   <form>
       <input type="text" name="nombre">
       <input type="submit"> 
   </form>
......
</html>

并且它工作正常,发送和接收 json 格式的帖子数据,我的问题是,当我尝试将表单保存在不同的 html 中,然后通过按钮或其他东西检索它时,我的调用是使用“GET”参数完成的,并且我不知道为什么。

我已经阅读了.load()来自 jquery doc 的文章,也有很多来自这个网站的帖子,但我似乎没有找到任何信息,我还想提一下,我知道 .load 默认是 get,我发送一些参数让它发布,这个我是如何从外部档案中获取表格的

$('#target').load('php/searchForm.html',{algo:'algo'});

然后我的表单现在加载到我的 html 上,但是当我提交它时,我的调用更改为“GET”。PD。对不起我的英语我不是美国人也不是英语谢谢。

4

3 回答 3

0

经过这么多寻找后,我得到了这个解决方案 jQuery 通过表单提交在 div 中加载 relaoding 内容

终于解决了,我的问题就这样解决了,我将两个文件“index”和“externalForm”移动到同一个目录,它们都在标题上,瞧我可以加载一个外部表单然后使用它

于 2013-07-27T17:58:13.510 回答
0

GET 是发送表单的默认方式,您的表单可能以常规方式提交,而不是使用 javascript,因为存在语法错误,如果动态插入表单,您将需要委托事件处理程序:

$('#target').on('submit', '#JqPostForm', function (e) {
    e.preventDefault();
    $("#despliegaresultados, #paginacion").empty();
    $.post("php/prueba.php", $('#JqPostForm').serialize(), function (data) {
        $.each(data, function (i, item) {

            // NOTE: Ajax is async, the below values are only accessible
            //       after the ajax call has completed

            var total = item.total,
                datos = item.datos;
        });
    }, "json");
});
于 2013-07-27T04:09:38.883 回答
0

你忘了提

<form method="POST">
于 2013-07-27T04:09:53.553 回答