Question: I am quite green when it comes to AJAX and am trying to get an email address from an ASP.Net code behind function 

When using the below code I am getting the error as per the title of this issue. 

This is the code I am using 

```
$('.txtRequester').focusout(function () {
 console.log("textBox has lost focus");
 function ShowCurrentTime() {
 $.ajax({
  type: "POST",
  url: "Default.aspx/FindEmailAddress",
  data: '{id: "' + $("txtRequester").val + '" }',
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: OnSuccess,
  failure: function (response) {
    alert(response.d);
     }
   });
 }
  function OnSuccess(response) {
   alert(response.d);
  }
});

```

which is an adaptation of the code from this site. 

[ASP.Net Snippets](http://www.aspsnippets.com/Articles/Call-ASPNet-Page-Method-using-jQuery-AJAX-Example.aspx)

When changing the line 

`success: OnSuccess` to `success: alert(response)` or `success: alert(data)`

I get the error up, but if I use `success: alert("ok")` I get the message saying ok so I suspect that I am getting into the function as below.

```
<System.Web.Services.WebMethod()> _
Public Shared Function FindEmailAddress(ByVal id As String) As String
Dim response As String = GetEmail(id)
Return response
End Function

```

I would be extremely grateful if someone to help me and let me know where I am going wrong on this one. 

thanks

Answer: 
I think you have can check the state of failure by using this code below as I think there is wrong syntax used by you. 

```
$('.txtRequester').focusout(function () {
        console.log("textBox has lost focus");
        function ShowCurrentTime() {

            $.ajax({
                type: "POST",
                url: "Default.aspx/FindEmailAddress",
                data: JSON.stringify({id: ' + $(".txtRequester").val() + ' }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data, status, header){
                 console.log(data);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        }

    });

```

then definitely you will get error response, if your success won't hit.
Change `$('.txtRequester')` to `$('#txtRequester')`

and 

Change `$("txtRequester").val` to `$('#txtRequester').val()`