Validate Plugin - cant get post data to be json
No matter what I have tried, I can not get the post from the remote validation rule to go across as JSON.
Setting contentType: 'application/json; charset=utf-8' has absolutely no effect. The data still gets sent across in querystring/post data format. (EX: UserName=bdbedbdebs&domain=@userdomain) Then I get this error:
{"Message":"Invalid JSON primitive: UserName.","StackTrace":"
at System.Web.Script.Serialization.JavaScriptObjectDeserializer
.DeserializePrimitiveObject()
The rest is omitted for clarity. I am able to get this to work with my own calls to ajax, just not the validator plugin. This has become very frustrating.
Here is my validator rule:
- UserName: {
- required: true,
- minlength: 2,
- regex: "^[a-zA-Z]{1}[w]{0,15}[.-_]?[w]{1,25}$",
- remote: {
- //url: '../Services/GeneralServices.asmx/IsUserNameAvailable',
- url: 'CreateUser.aspx/IsUserNameAvailable',
- type: 'POST',
- contentType: 'application/json; charset=utf-8',
- dataType: 'json',
- data: {
- domain: function() {
- if(typeof ($("#lblUserDomain").val()) !== 'undefined')
- return $("#lblUserDomain").val();
- else
- return $("#ddlUserDomains :selected").text();
- }
- }
- }
- }