2011-10-10 54 views
1

每次我提出這種形式,而不是將其發送到服務器,由於某種原因,重新加載頁面,並添加所有的數據作爲GETjQuery的不發送的形式正確

如果有人看到了我想知道在下面的代碼錯誤。

$("#updatebusiness").live('click', function(event){ 

     var tradingname = $('#tradingname').attr('value'); 
     var website  = $('#website').attr('value'); 
     var address  = $('#address').attr('value'); 
     var phonenumber = $('#phonenumber').attr('value'); 
     var email  = $('#email').attr('value'); 
     var postcode = $('#postcode').attr('value'); 
     var state = $('#state').val(); 
     var city = $('#city').attr('value'); 
     var leadstatus = $('#leadstatus').val(); 

     var sendemail = $('#sendemail').val(); 
     var whichemail = $('#whichemail').val(); 

     var notes  = $("#notes").val(); 
     var description  = $("#description").val(); 


     var callback = $('#callback').val(); 
     var callbackdate = $('#callbackyear').val()+"-"+$('#callbackmonth').val()+"-"+$('#callbackday').val(); 
     var callbacktime = $('#callbackhour').val()+":"+$('#callbackmin').val(); 

     var companyname = $('#companyname').attr('value'); 
     var acnabn  = $('#acnabn').attr('value'); 
     var position = $('#position').attr('value'); 
     var title  = $('#title').val(); 
     var firstname = $('#firstname').attr('value'); 
     var lastname = $('#lastname').attr('value'); 
     var industry = $('#industry').val(); 
     var subcategory = $('#subcategory').val(); 
     var suburb1  = $('#suburb1').attr('value'); 
     var suburb2  = $('#suburb2').attr('value'); 
     var suburb3  = $('#suburb3').attr('value'); 
     var suburb4  = $('#suburb4').attr('value'); 
     var suburb5  = $('#suburb5').attr('value'); 
     var suburb6  = $('#suburb6').attr('value'); 
     var ms1   = $('#ms1').attr('value'); 
     var ms2   = $('#ms2').attr('value'); 
     var ms3   = $('#ms3').attr('value'); 
     var ms4   = $('#ms4').attr('value'); 
     var rcb1  = $('#rcb1').attr('value'); 
     var rcb2  = $('#rcb2').attr('value'); 
     var rcb3  = $('#rcb3').attr('value'); 
     var rcb4  = $('#rcb4').attr('value'); 
     var hotofferone = $('#hotoffer1').attr('value'); 
     var hotofferrcb = $('#hotofferrcb').attr('value'); 

     var hotofferstartdate = $('#startday').val()+"-"+$('#startmonth').val()+"-"+$('#startyear').val(); 
     var hotofferfinishdate = $('#finishday').val()+"-"+$('#finishmonth').val()+"-"+$('#finishyear').val(); 

     var terminalid = $('#terminalid').val(); 
     var bankname = $('#bankname').attr('value'); 
     var bsb   = $('#bsb').attr('value'); 
     var cardtype = $('#cardtype').attr('value'); 
     var cardexpire = $('#cardmonth').val()+"/"+$('#cardyear').val(); 

     if($('#terminalverified').is(':checked')) { 
     var terminalverified = "Yes"; 
     } else { 
     var terminalverified = "No"; 
     } 

     var mobilenumber = $('#mobilenumber').attr('value'); 
     var faxnumber = $('#faxnumber').attr('value'); 
     var membershiptype = $('#membershiptype').attr('value'); 
     var keywords = $('#keywords').attr('value'); 
     var merchantid = $('#merchantid').attr('value'); 
     var bacname  = $('#bacname').attr('value'); 
     var bacnumber = $('#bacnumber').attr('value'); 
     var crnumber = $('#crnumber').attr('value'); 
     var cvv   = $('#cvv').attr('value'); 
     var incardallocation = $('#incardallocation').attr('value'); 


     var postaladdress = $("#postaladdress").attr('value'); 
     var postalcity  = $("#postalcity").attr('value'); 
     var postalstate  = $("#postalstate").attr('value'); 
     var postalcode  = $("#postalcode").attr('value'); 
     var AMStatus  = $("#AMStatus").attr('value'); 

     if(usertype == 3 || usertype == 1) 
     { 
     var chosenusername  = $("#chosenusername").attr('value'); 
     var chosenpassword  = $("#chosenpassword").attr('value'); 
     } 
     else 
     { 
     var chosenusername  = null; 
     var chosenpassword  = null; 
     } 

     if(usertype == 1) 
     { 
     var leadowner = $("#leadowner").val(); 
     } 
     else 
     { 
     var leadowner = $userid; 
     } 
     $.ajax({ 
      type: "POST", 
      url: "system/classes/core.php", 
      data: "task=updatebusinesslead&tradingname="+encodeURIComponent(tradingname)+"&website="+website+"&address="+address+"&phonenumber="+phonenumber+"&email="+email+"&postcode="+postcode+"&city="+city+"&state="+state+"&leadstatus="+leadstatus+"&sendemail="+sendemail+"&whichemail="+whichemail+"&callback="+callback+"&callbackdate="+callbackdate+"&callbacktime="+callbacktime+"&userid="+leadowner+"&companyname="+encodeURIComponent(companyname)+"&acnabn="+acnabn+"&position="+position+"&title="+title+"&firstname="+firstname+"&lastname="+lastname+"&industry="+industry+"&subcategory="+subcategory+"&suburbone="+suburb1+"&suburbtwo="+suburb2+"&suburbthree="+suburb3+"&suburbfour="+suburb4+"&suburbfive="+suburb5+"&suburbsix="+suburb6+"&msone="+ms1+"&mstwo="+ms2+"&msthree="+ms3+"&msfour="+ms4+"&rcbone="+rcb1+"&rcbtwo="+rcb2+"&rcbthree="+rcb3+"&rcbfour="+rcb4+"&hotofferone="+hotofferone+"&hotofferrcb="+hotofferrcb+"&hotofferstartdate="+hotofferstartdate+"&hotofferfinishdate="+hotofferfinishdate+"&terminalid="+terminalid+"&bankname="+bankname+"&bsb="+bsb+"&cardtype="+cardtype+"&cardexpire="+cardexpire+"&terminalverified="+terminalverified+"&mobilenumber="+mobilenumber+"&faxnumber="+faxnumber+"&membershiptype="+membershiptype+"&keywords="+keywords+"&merchantid="+merchantid+"&bacname="+encodeURIComponent(bacname)+"&bacnumber="+bacnumber+"&crnumber="+crnumber+"&cvv="+cvv+"&incardallocation="+incardallocation+"&postaladdress="+postaladdress+"&postalcity="+postalcity+"&postalstate="+postalstate+"&postalcode="+postalcode+"&notes="+encodeURIComponent(notes)+"&description="+encodeURIComponent(description)+"&chosenusername="+chosenusername+"&chosenpassword="+chosenpassword+"&AMStatus="+AMStatus+"&usertype="+usertype, 
      success: function(data){ 
       if((data) == 1) 
       { 
        loadadminlayout(); 
       // alert(data); 
       } 
       else 
       { 
       alert(data);  
       } 
      } 
     }); 
     //continuebusinesslead(); 
return false; 
}); 
+0

您是否看到Firebug中的任何腳本錯誤? – SLaks

+4

你這樣做是艱難的。看看['.serialize()'](http://api.jquery.com/serialize/)。 – thirtydot

+0

@thirtydot正是!看到我的帖子下面。 – watzon

回答

3

你有沒有試過在$ .post()方法中使用jQuery構建?

,你可以很容易地縮小代碼到:

$("#updatebusiness").live('click', function(event){ 
$.post("system/classes/core.php", $("#your-form-id").serialize(), function(data) { 
if((data) == 1) { 
loadadminlayout(); 
// alert(data); 
} 
else 
{ 
alert(data);  
} 
}); 
}); 
+0

謝謝,不,我什至不知道這個 – RussellHarrower

+0

高興地幫助:) – watzon

0

是您的$(「#updatebusiness」)的普通鏈接(<a href="#" id="updatebusiness">用戶必須點擊如果是,那麼你應該添加和event.preventDefault()預防?從去任何地方,或者更確切地說,瀏覽器使用<button>代替

也:嘗試.serialize(),而不是

0

既然你正在做一個POST阿賈克斯期待的「數據」您是對象的屬性! p分配它。您正在設置發佈的方法,然後將您發佈的網址設置爲get。您需要序列化您的表單並將其分配給data屬性,或者您需要將您的ajax類型更改爲「GET」