繁体   English   中英

提交表单后JQuery发送帖子请求?

[英]JQuery send post request after submit form?

你好朋友这是我的代码表单提交然后发送帖子链接但表单提交成功后不发送帖子链接。

document.getElementById("pitch_image_path_form").submit(function(e){

$.post("submit_investorform.php",{'flage':'getallimagesfromselectedid','form':'pitch_image_path_form'},function(result){
                    $("#pitch_image_path_showalldatafromid").html(result);
            });
            e.preventDefault();
    });

这是我的代码表单提交但邮件请求不发送。

.submit()是一个jQuery函数,所以你需要在jQuery包装器中包装你的$("#pitch_image_path_form")[0] ,如下所示:

$($("#pitch_image_path_form")[0]).submit(function(){

亲爱的renishkhunt请尝试此代码。 这对我来说是完全有用的。

    $("#pitch_image_path_form").ajaxSubmit({ success: function(){ 
            $.post("submit_investorform.php",{'flage':'getallimagesfromselectedid','form':'pitch_image_path_form'},function(result){
                    $("#pitch_image_path_showalldatafromid").html(result);
                });
     } });

请检查此链接这是教程。

http://malsup.com/jquery/form/

在DOM中没有submit()事件,你正在混合DOM和jQuery

更改

document.getElementById("pitch_image_path_form").submit

$("#pitch_image_path_form").submit
$("pitch_image_path_form").submit(function(e){
e.preventDefault();
$.post(
    "submit_investorform.php",
    {'flage':'getallimagesfromselectedid','form':'pitch_image_path_form'}
    , function(result) { $("#pitch_image_path_showalldatafromid").html(result); }
);

});

因为DOM不支持submit(),所以在DOM中有commit()函数。 当你最后一次问这个时,答案是一样的。

当您调用.submit() ,它会使用<form>的指定操作发布<form>

您可能希望通过使用event.stopPropagation();来停止传播event.stopPropagation(); event.preventDefault(); 或者return false; 在你的功能结束时。

 $("#pitch_image_path_form").submit(function(event){
        event.stopPropagation(); 
        event.preventDefault();

        //Your .post()

        return false;
    });

另外,正如epascarello所指出的, .submit()是一个jQuery函数。

如果你想使用它,通过在submit()之前删除[0]在jQuery对象上使用它, 因为你不应该有多个具有相同ID的元素

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM