Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Javascript Ajax call not firing, struggling to debug.

$
0
0

I apologise in advance as this is a noob question but this is the first time I have done Ajax and I cannot get it to work. I'm hoping that some experienced person on here might just look at it and know whats wrong with it straight away.

My javascript code is:

function UpdateStudent(e) {
       name = $("#txtName").val();
       fee = $("#txtFee").val();$.ajax({
           type: "POST",
           url: "StudentWebService.asmx/UpdateStudent",
           data: "{'WorkplanID':'" + id + "', 'WPUser':'" + name + "', 'Task':'" + fee + "'}",
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           success: function (response) { //success: alert('success') works
               var result = response.d;
               alert('Success');
               if (result > 0) {$("#name", row).text(name);$("#fee", row).text(fee);
                   row.removeClass("highlightRow");
                   CloseEditStudentDialog();
               }
               else {
                   alert('There is some error during update');
               }
           },
           failure: function (msg) {
               alert(msg);
           }
       });
       return false;
   }

Is there anything obvisouly wrong with that? When I click update button nothing happens. Or is there a way I can debug this properly? In IE developer mode it just highlights the whol ajax code and then bypasses it as though it runs. But nothing happens - the CloseEditStudentDialog never gets fired.

I know the webs service works because in VS2010 if I run the web service code it lets me enter and update values no problem. Here is my c# code if needed. Many thanks for any help.

[WebMethod]
    public int UpdateStudent(int WorkplanID, string WPUser, string Task)
    {
        SqlConnection con = null;
        //string constr = @"Server=TestServer; Database=SampleDB; uid=waqas; pwd=123";
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["PublicHealthCMSConnectionString"].ConnectionString;
        string query = "UPDATE Workplan SET WPUser = @WPUser, Task = @Task WHERE WorkplanID = @WorkplanID";

        con = new SqlConnection(constr);
        SqlCommand command = new SqlCommand(query, con);
        command.Parameters.Add("@WPUser", SqlDbType.VarChar).Value = WPUser;
        command.Parameters.Add("@Task", SqlDbType.VarChar).Value = Task;
        command.Parameters.Add("@WorkplanID", SqlDbType.Int).Value = WorkplanID;

        int result = -1;
        try
        {
            con.Open();
            result = command.ExecuteNonQuery();
        }
        catch (Exception)
        { }
        finally
        {
            con.Close();
        }
        return result;
    }    

I should say the id variable is defined and populated earlier.

Many thanks


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>