2013-03-02 53 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>