jQuery and AJAX

Discussion in 'HTML / PHP / JavaScript / CSS' started by kingwoodbudo, Apr 23, 2012.

  1. Hello,

    I'm working on some code that does a simple database call and returns json data. I tested the webservice on my local machine and it returned the data fine. When I call the webservice from jQuery I get an error: 500 Internal Server Error.

    Here is my webservice:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string SignIn()
    {

    List<SignInCredentials> oList = new List<SignInCredentials>();
    string queryString = "SELECT UserName, UserLastLogin FROM UserLogin;";

    using (SqlConnection connection =
    new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ToString()))
    {
    SqlCommand command =
    new SqlCommand(queryString, connection);
    connection.Open();

    SqlDataReader reader = command.ExecuteReader();

    // Call Read before accessing data.
    while (reader.Read())
    {

    SignInCredentials sic = new SignInCredentials();
    sic.Username = reader["UserName"].ToString();
    sic.UserLastLogin = reader["UserLastLogin"].ToString();
    oList.Add(sic);

    }

    // Call Close when done reading.
    reader.Close();
    }


    // Return JSON data
    JavaScriptSerializer js = new JavaScriptSerializer();
    string strJSON = js.Serialize(oList);
    return strJSON;
    }

    My AJAX call:
    $(document).ready(function () {
    $("#signIn").bind("click", function () {
    $("#signInSection").empty();
    $("#signInSection").append('Sign In Status:');
    $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "UserVerfication.asmx/SignIn",
    data: '{ }',
    dataType: "json",
    success: function (data) {


    $("#signInSection").append(data.UserName);


    },
    error: function (jqXHR, textStatus, errorThrown) {
    alert(jqXHR + ":" + errorThrown);
    }

    });
    })
    });


    Thanks for anything you can suggest.
     
  2. Figured it out

    My web service was spelled incorrectly causing a 404 error.
     
  3. martino

    martino DiscountASP.NET Staff

    Glad you have resolved your issue and thank you for letting us know about your solution.
     

Share This Page