Created
August 3, 2016 09:27
-
-
Save z2015/82b5fa85849fd888286d160c6b7f44cf to your computer and use it in GitHub Desktop.
jQuery post json data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.serializeObject = function() { | |
var o = {}; | |
var a = this.serializeArray(); | |
$.each(a, function() { | |
if (o[this.name]) { | |
if (!o[this.name].push) { | |
o[this.name] = [o[this.name]]; | |
} | |
o[this.name].push(this.value || ''); | |
} else { | |
o[this.name] = this.value || ''; | |
} | |
}); | |
return o; | |
}; | |
var myJSObject = $('#form').serializeObject(); | |
$.ajax(url, { | |
data : JSON.stringify(myJSObject), | |
contentType : 'application/json', | |
type : 'POST', | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment