I’m trying to get the value of the first value pair from a form submission via AJAX. Here’s what the var Formdata looks like (id=4&name=somename&blah=blah). How do I get the id value of 4? As you can see I was trying several ways but had no luck. Any suggestion would be much appreciated, thanks in advance.
$("#updatetask").validate({
submitHandler: function() {
var formdata = $('#updatetask').serialize();
var fistkey = formdata.split("&",1);
var tester = fistkey.slice(-1);
alert(tester);
/*
$.post('/tasks/AJAXupdate', $('#updatetask').serialize(), function(data){
var retur开发者_StackOverflow中文版nMsg = data.replace(/^\s+|\s+$/g, '');
if (returnMsg == 'error'){
alert(returnMsg+': Unable to update task.');
}else{
parent.$.fancybox.close();
}
});*/
return false;
}
});
});
Can't you simply $('#updatetask :input:eq(0)').val()
instead of serializing it and parsing the string?
精彩评论