How do I submit form values with Xui framework's xhr object?
I'm giving the Xui javascript framework for mobile apps a spin and I'm stuck on form submission using its xhr ajax object. I'm trying to submit username and password form values to a php script. This is my code:
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);}
})
});
});
Could anyone tell me what's wrong with this and how I could fix it?
If you want to submit your form with a form-urlencoded
content type, you should not use JSON.stringify()
but create a url-encoded string instead. Example:
var data = "";
replyForm.find('#xuiForm input').each(function(elem){
data += elem.name + "=" + encodeURIComponent(elem.value) + "&";
});
精彩评论