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

时间:2013-10-24 12:14:15

标签: javascript jquery

Hello Friends这是我的代码,用于表单提交然后发送帖子链接,但表单提交成功后不发送帖子链接。

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();
    });

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

6 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:1)

亲爱的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/

答案 2 :(得分:0)

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

变化

document.getElementById("pitch_image_path_form").submit

$("#pitch_image_path_form").submit

答案 3 :(得分:0)

$("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); }
);

});

答案 4 :(得分:0)

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

答案 5 :(得分:0)

当您致电.submit()时,它会使用<form>的指定操作发布表单。

您可能希望在功能结束时使用event.stopPropagation();event.preventDefault();return false;停止传播。

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

        //Your .post()

        return false;
    });

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

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

相关问题