I have a JSON request that checks the server if the user name has already been taken during the registration process.
This is a jQuery call:
// Quick check availability of user name $ ("# txtUserName"). $ ("($ #") "$$" ("# txtUserName"). Val () == ""); $ .ajax ({ Type: 'post', url: '/ login / checkusername', data: "{userName:") + "'}", content type: "app / jason; charset = utf-8", datatype: "jason" Success: Function (message) {// Set span checking text, user knows if if only available (if "CSS" ({"color": "red", "font-weight": "bold", "font -size ":" small "," padding-lesson "(" non-organ ");} and {$ (" # user no. ("Color": "left"): "$ 5" ("# userNameCheck"). "Green", "font-weight": "bold", "font-size": "Small", "padding-left": "5px"}; $ ("# UserNameCheck") text ("Disponibile").}}, Error: function (errormessage) {// it's just to see Whether everything is working before removing $ J ("# username check"). Text (errormess.responseText);}})}};
and This is the controlling process that will serve the request
[http post] Public Jensourge Lt checkuser name (string username) {if (membership.GetUser (userName)) == faucet) back Jason (false); And Jason (true) returned; }
Anyway I do not understand why I am getting error 500 from server. Seeing it with Fiddler, I can see that the RAW request is
POST http: // localhost: 1037 / login / checkUserName HTTP / 1.1 Host: Localhost: 1037 Connection: Keep-alive Referrer: Http: // localhost: 1037 / login / register content-length: 22 Origin: http: // localhost: 1037 with X-Requested: XMLHttpRequest Content-Type: Application / Jason; Accept Charset = UTF-8: Applications / Jason, Text / Javascript, * / * User-Agent: Mozilla / 5.0 (Windows; U; Windows NT 5.1; N-US) Apple WebKat / 534.3 (KHML, like Gecko) Chrome / 6.0 .472.63 Safari / 534.3 Accepting-Encoding: gzip, deflate, sdch Accepted-language: IT, this; Q = 0.8, en-US; Q = 0.6, en; Q = 0.4 Accept-charset: ISO-8859-1, UTF-8; Q = 0.7, *; Q = 0.3 {username: 'sample_user'}
but the controller operation receives a null parameter for the user name.
Edit
I see it through the fielder and also apply breakpoint to the code.
The error returned to the customer
The value can not be zero parameter name: Username
Please note that The parameter name in the error is not preserving the original case. Is it the behavior of the membership provider or should I reduce the case of the parameter?
You are sending requests as JSON, but there is nothing in the server that understands this format Or believe You have a controller action, which expects application / x-www-form-urlencoded
content type instead, try it instead:
data: {username : $ ('# TxtUserName'). Val ()}, Content Type: 'application / x-www-form-urlencoded',
It also benefits the encoding standards sent to servers to properly handle URLs To pick up, which was not achieved using string combinations in your version.
Comments
Post a Comment