0

I am developing an application in which I am retrieving data from the database into GirdView. Now when any user clicks on the Get City, it should return the city name of that particular row.

enter image description here

But i am getting the following error:

enter image description here

Following is my script code:

 <script>
    $(document).ready(function () {
        $("a").one("click", function (evt) {
            debugger;
            var stu_id = $(evt.target).closest("tr").children(":first-child").text();
            $.ajax({
                type: "POST",
                url: 'WebForm1.aspx/get_city',
                data: "{'stuid':'" + stu_id +"'}",
                async: false,
                contentType: "application/json; charset=utf-8",
                success: function (final) {
                    debugger;
                    $("#LblCity").append(final.d + "<hr/>");
                },
                error: function () {
                    debugger;
                    alert('error');
                }
            });
        });
    });
</script>

My WebForm1.aspx.cs page code:

[WebMethod]
    public static string Get_City(int stuid)
    {
        MyDatabaseEntities MyDb = new MyDatabaseEntities();

        var data = from db in MyDb.Students
                   where db.ID == stuid
                   select db.City;
        return data.SingleOrDefault().ToString();
    }
18
  • What is the error? Your tooltip is showing the jQuery source for $.ajax, not an error message. Have you checked the console? Commented Apr 30, 2014 at 7:19
  • I am sorry for that, the error is URL is undefined. @RoryMcCrossan Commented Apr 30, 2014 at 7:20
  • @RoryMcCrossan nothing is happening when i am clicking on the Get City. please help. Commented Apr 30, 2014 at 7:21
  • 1
    Have you put breakpoint inside webmethod to see if the code goes there? Commented Apr 30, 2014 at 7:23
  • 1
    Visual Studio 2013, .NET framework (latest) @Deepsy Commented Apr 30, 2014 at 11:08

1 Answer 1

1

I solved it. I am using Visual Studio 2013 so I just update the RouteConfig.cs file with the following code:

settings.AutoRedirectMode = RedirectMode.Off;

Now everything is running fine. Thanks for helping me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.