tags:

views:

17

answers:

1

hi, I am in situation where i m nt able to figure out where i am wrong. I am calling web service using jquery.It is working fine as it call webmethod done the operation .but it call function service failed on error clause than success in $.ajax call

it should alert me 'hi' if the service is successfule.but it is calling ServiceFailed function ,but in database values are updated perfectly as i enter and passed to service using $.ajax call

my j query code is fallow

function ActionSendRequest() {

        if (globArray.length > 0) {
            alert(globArray.length);
            document.getElementById('lblError').innerHTML = 'Please Wait.....';
            for (var i = 0; i < globArray.length; i++) {
                var Lot = globArray[i];
                var Price = document.getElementById('prc' + globArray[i]).value;
                var Quantity = document.getElementById('qty' + globArray[i]).value;
                $.ajax({
                    type: "POST",
                    url: "../test.asmx/AddModReqSample", 
                    data: "{Lot:'" + Lot + "',Price:'" + Price + "',Quantity:'" + Quantity + "'}", 
                    contentType: "application/json; charset=UTF-8", 
                    dataType: "xml", 
                    processdata: true, 
                    success: function (msg) {
                        ServiceSucceeded(msg);
                    },
                    error: ServiceFailed
                });
            }
        }
    } 
    function ServiceSucceeded(result) {
        alert('hi');
        if (result.d == "Error") {

        }
        else if (result.d == "Successfully") {

        }
    }
    function ServiceFailed(result) {
        document.getElementById('lblError').innerHTML = 'Service call failed: ' + result.status + '' + result.statusText;
    }

And My WebService Method is fallows

[WebMethod(EnableSession = true)]

public string AddModReqSample(int Lot, decimal Price, decimal Quantity) {

        if (SessionLog.UID != 0)
        {
            return objDataStore.ReqSample(Lot, SessionLog.UID, Quantity,Price);

        }
        else return "Please Login to the System";

} The Final Messge i got is like this Service call failed: 200 OK

A: 

After looking at the response and code for more time, i got the problem ,my webmethod response in the json format while i am looking data in xml format,as u can see in above code dataType: "xml" which i change to json and now i am getting it correctly. thanks every one