2013-03-02 51 views
0

我使用給ajaxForm擴展提交表單與AJAX如下如何更改提交使用後給ajaxForm

var options = 
     { 
      url:'<?php echo site_url('user/ajaximage')?>', 
      dataType: 'json', 
      success: function(data) 
      { 
       if(data.messagecode==1) 
       { 
        $(".wrap label").hide(); 
        $("#preview").html("<img src='"+data.content+"'class='preview'>"); 
        $("#errormessagepic").hide(); 
       } 
       else if(data.messagecode==0) 
       { 
        $("#errormessagepic").html(data.content); 
        $("#preview").html('<img width="100" height="100" src="<?php echo base_url();?>/images/avatar_generic.png" />');   
       } 
       //$('#SignupForm').resetForm(); 
       //$("#SignupForm").attr('action','<?php echo site_url('user/individualprofile')?>'); 
      } , 
     }; 
     $("#SignupForm").ajaxForm(options); 
     $("#SignupForm").submit(); 

但阿賈克斯提交後我要重新發送的形式不是'之外的另一個URL形式的價值但它不起作用。任何幫助

回答

0

好,所以你想發佈一個表單使用Ajax到兩個不同的網址。我不知道你的擴展,但我可以告訴你如何做到這一點。

1-創建一個函數並運行此功能時用戶點擊提交 < - 輸入類型=「按鈕」名稱=「提交」值=「提交」的onclick =「post_form()」 - />

2-創建函數體中,該功能將數據提交到兩個URL

function post_form(){ 

    // save the values in text boxes in variable 

    var val1=$("#text1").val(); 
    var val2=$("#text2").val(); 

    var data={name:val1,age:val2}; 

    var url1="savedata.php"; 
    var url2="updatedata.php"; 

    $.post(url1,data, function(response){ 

    alert(response); 

    // so when the form is submited to ur1 this callback function runs and here you can submit it to another url 

    $.post(url1,data,function(response){alert(response)}); 

    }); 

    } 

</script>