Skip to content

Instantly share code, notes, and snippets.

@gmemstr
Created August 20, 2017 20:19
Show Gist options
  • Save gmemstr/c19f58f43e5ed3c7a5d6a0ae31a18008 to your computer and use it in GitHub Desktop.
Save gmemstr/c19f58f43e5ed3c7a5d6a0ae31a18008 to your computer and use it in GitHub Desktop.
+// Converts ajax POST to JavaScript object
+var BodyToObject = function(body) {
+ var res = new Object;
+ body = body.split("&"); // param1=X,param2=X
+ console.log(body);
+ for (var i = body.length - 1; i >= 0; i--) {
+ var vals = body[i].split("="); // param2,X,param1,X
+ for (var k = vals.length - 2; k >= 0; k--) {
+ res[vals[k]] = vals[k + 1] // *hopefully* {param1:X,param2:X}
+ }
+ }
+ return res;
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment