jquery ajax call to check data from database always return an error - .NET -


i developping functionality whereby users can check if email exist in database( on registration page ).

basically testing purposes, have added user email address 'test@yopmail.com' in database manually.

i trying check via ajax if email exist. here codes using:

    [webmethod(messagename = "checkemailavailability", description = "check whether email available.")]     public string checkemailavailability(string email)     {         var checkemailavailabilityresult = string.empty;          try         {             var membershipuser = membership.getusernamebyemail(email);              if (!string.isnullorwhitespace(membershipuser))             {                 checkemailavailabilityresult = "email_already_exist";             }             else             {                 checkemailavailabilityresult = "email_not_exist";             }         }         catch (exception ex)         {             checkemailavailabilityresult = "unexpected_error";         }          return checkemailavailabilityresult;     }      #endregion 

my ajax is:

  $('#test_json').click(function(){    $.ajax({     type: "post",     url: "http://locahost/webservices/email_availability/email_availability_v1_1.asmx/checkemailavailability",     data: { email: json.stringify('test@yopmail.com')},     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: function(data){          alert('data');      },      error: function(data){ alert('test'+data); }   });  }); 

the following being alerted: test[object]

what doing wrong? please help

you don't need use json.stringify on string value.

data: { email: json.stringify('test@yopmail.com')}, 

change to

data: { email: 'test@yopmail.com'}, 

and print out what's going on in error, need change parameters of error function. first param xhr object, want inspect second , third params see failing.

type: function( jqxhr jqxhr, string textstatus, string errorthrown )

from jquery docs: https://api.jquery.com/jquery.ajax/


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -