Created
June 19, 2012 09:44
-
-
Save tugberkugurlu/2953296 to your computer and use it in GitHub Desktop.
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
<form action="/api/values" method="post"> | |
<input type="text" name="value" /> | |
<input type="submit" value="Submit" /> | |
</form> | |
<form id="fooForm" action="/api/values" method="post"> | |
<input type="text" name="value" /> | |
<input type="submit" value="Submit" /> | |
</form> | |
@section scripts{ | |
<script type="text/javascript"> | |
$(function () { | |
$("#fooForm").submit(function (e) { | |
$.ajax({ | |
url: this.action, | |
type: "POST", | |
//None of the options below works | |
//data: JSON.stringify({ value: $(this).find("input[name=value]").val() }) | |
data: ({ value: $(this).find("input[name=value]").val() }) | |
}); | |
e.preventDefault(); | |
}); | |
}); | |
</script> | |
} |
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
without JSON.stringify | |
-------------------------------------- | |
POST http://localhost:2547/api/values HTTP/1.1 | |
Host: localhost:2547 | |
Connection: keep-alive | |
Content-Length: 9 | |
Origin: http://localhost:2547 | |
X-Requested-With: XMLHttpRequest | |
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7 | |
Content-Type: application/x-www-form-urlencoded | |
Accept: */* | |
Referer: http://localhost:2547/ | |
Accept-Encoding: gzip,deflate,sdch | |
Accept-Language: en-US,en;q=0.8 | |
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 | |
Cookie: .ASPXAUTH=502750FAA18C2116E8F6F952CF16DE324DDA73B64758CD7B28B7026E65377F3EFFB6722B004805E60F2324B061BA2298DF31E32D230D9F189C693E060DA0B83DC1FF894B5589065AA7630758DC513732096E0D9DDFA051E467E029A91B9DD6A793212585573D88280DAB9BA0CB73A43732B2D8E6C7D896D56E0E92F60B209968E076A78E14965BC9C38B22B07D49DD75 | |
value=fff | |
with JSON.stringify | |
------------------------------------- | |
POST http://localhost:2547/api/values HTTP/1.1 | |
Host: localhost:2547 | |
Connection: keep-alive | |
Content-Length: 15 | |
Origin: http://localhost:2547 | |
X-Requested-With: XMLHttpRequest | |
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7 | |
Content-Type: application/x-www-form-urlencoded | |
Accept: */* | |
Referer: http://localhost:2547/ | |
Accept-Encoding: gzip,deflate,sdch | |
Accept-Language: en-US,en;q=0.8 | |
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 | |
Cookie: .ASPXAUTH=502750FAA18C2116E8F6F952CF16DE324DDA73B64758CD7B28B7026E65377F3EFFB6722B004805E60F2324B061BA2298DF31E32D230D9F189C693E060DA0B83DC1FF894B5589065AA7630758DC513732096E0D9DDFA051E467E029A91B9DD6A793212585573D88280DAB9BA0CB73A43732B2D8E6C7D896D56E0E92F60B209968E076A78E14965BC9C38B22B07D49DD75 | |
{"value":"foo"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment