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

jquery web service ajax problem

$
0
0

I have added a web service to my asp.net project.  The  web service calls a stored procedure via entity framework.  I tested the webservice and it works as expected.  I did remember to remove the comments to all allow for scripts service.  The web service class is in the App_Code folder so I added the ../. The ajax code is below: I added an alert to make sure the data value passed is correct.  Despite my best efforts I get an error.  The question is what have I screwed up? 

Tom

   $("#cmdSubmit").click(function () {
                       alert($('#txtCurID').val());
                       $.ajax({
                           type: "POST",
                           url: "../wsGetDefCount.asmx/GetApparatusTroubleTicketCountByID",
                            data: "{ 'ID': '" + $("#txtCurID").val() + "' }",
                           contentType: "application/json; charset=utf-8",
                           dataType: "json",
                           success: OnSuccess,
                           error: function (xhr, status, error) {
                               // Display a generic error for now.
                               alert("AJAX Error!");
                           }
                       });
                   });

 function OnSuccess(data, status) {
               alert(data.d);
           }

Here's the web service.

 [System.Web.Script.Services.ScriptService]
public class wsGetDefCount : System.Web.Services.WebService {
    Dept clsDept = new Dept();
    sfhsEntities ctx = new sfhsEntities();

    public wsGetDefCount () {
        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
    public int GetApparatusTroubleTicketCountByID(int ID) {
        using (sfhsEntities context = new sfhsEntities())
        {
            System.Data.Objects.ObjectParameter AoutputParameter = new System.Data.Objects.ObjectParameter("DefCount", typeof(int));
            ctx.GetApparatusTroubleTicketCountByID(ID, AoutputParameter);
            return (int)AoutputParameter.Value;
        }
    }
    
}


Viewing all articles
Browse latest Browse all 5678

Trending Articles