2011-09-05 24 views
0

我給移動應用程序的XUI javascript框架旋轉,我堅持表單提交使用其xhr ajax對象。我試圖將用戶名和密碼錶單值提交給php腳本。這是我的代碼:如何使用Xui框架的xhr對象提交表單值?

x$(window).load(function(){ 

    x$('#login').click(function(){ 
    var data = {}; 
    x$('#xuiForm input').each(function(elem){ 
     data[elem.name] = elem.value; 
    }); 
    var forminput = JSON.stringify(data); 

    x$('#xuiForm').xhr('http://localhost/demo/getform.php',{ 
     method:'post', 
     async: 'false', 
     data: forminput, 
     headers: {'Content-Type': 'application/x-www-form-urlencoded'}, 
     callback: function(){x$('#responsediv').html('inner',this.responseText);} 
     }) 
    }); 
}); 

誰能告訴我什麼不對的,我怎麼能解決這個問題?

回答

0

如果您想要提交表單的內容類型爲form-urlencoded,則不應使用JSON.stringify(),而應創建一個url編碼的字符串。例如:

var data = ""; 
replyForm.find('#xuiForm input').each(function(elem){ 
    data += elem.name + "=" + encodeURIComponent(elem.value) + "&"; 
}); 
相關問題