[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1326
  • Last Modified:

Calling asmx webserive using jquery ajax

I am making a call to webservice using Jquery ajax.

BUT It sometimes hits or sometimes does not hit.

I am confused. I am trying it for last one day.

Please help.

Client Side Code:

$.ajax({
        type: "POST",
        url: "../WebServices/GetFormsUtilization.asmx/IssuedFormsByETO",
        //data: "{FormsIssued:'"+jsonText+"'}",
        data: "{FormsIssued:'"+jsonText+"',Remarks:'"+EtoRemarks+"',Receipt_No:'"+qs["Receipt_No"]+"'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            //Redirect to the Previous Page
            return true;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert('error: ' + errorThrown);
                    return false;
        }
    });

SERVER SIDE CODE:
[WebMethod(EnableSession = true)]    
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public String IssuedFormsByTI(String FormsIssued, String Remarks, String Receipt_No)
    {
        //Session["SelectedForms"] = FormsIssued.ToString();
        try
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            List<String> ArrayOfIDs = serializer.Deserialize<List<String>>(FormsIssued);
            BLLFormsManagement ObjBLL = new BLLFormsManagement();
            //Check Form Balance
            Boolean IsSaved = ObjBLL.SaveFormsRequestDetails(ArrayOfIDs, Remarks, Receipt_No, Session["UserID"].ToString());
            return new JavaScriptSerializer().Serialize(String.Empty);
        }
        catch(Exception ex)
         {
             String exception = ex.ToString();
             return new JavaScriptSerializer().Serialize(String.Empty);
         }
    }
0
Dinesh Kumar
Asked:
Dinesh Kumar
  • 7
  • 3
  • 2
  • +2
1 Solution
 
Roopesh ReddyCommented:
Hi,

What do you mean by some times hit and some time not?

Are you getting any error?

Please provide more information!
0
 
Rajar AhmedConsultantCommented:
Response may be caching you can probably set it to false . try any of this option
 $(document).ready(function() {
  $.ajaxSetup({ cache: false });
});

$.ajax({url: "myurl", success: myCallback, cache: false});

Open in new window


For more Info,
http://stackoverflow.com/questions/168963/stop-jquery-load-response-from-being-cached
http://stackoverflow.com/questions/7750447/difference-between-ajaxcachefalse-and-ajaxsetupcachefalse-in-jqu

Meeran03
0
 
Dinesh KumarAuthor Commented:
roopeshreddy: I mean the ajax request does not hit (breakpoint)  the URL which exists in the webservice.

meeran03: I will test  your solution on the client side although I did try it on Server as follows [WebMethod(EnableSession = true, CacheDuration = 0)]    but this was not of use.

What I did:  I called Handler instead of asmx and it run well.

If you can help can you tell me what should I use handler or webservice?

thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Dinesh KumarAuthor Commented:
Hi, cache false not solving the problem.

I tried the following way:

$.ajax({
        type: "POST",
        url: "../WebServices/GetForms.asmx/IssuedForms",        
        data: "{FormsIssued:'"+jsonText+"',Remarks:'"+TiRemarks+"',No:'"+qs["No"]+"'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(msg) {    
        flag=1;
        //alert("Success");
        //window.history.back();              
            return true;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {                    
                    return false;
        }
    });
0
 
Dinesh KumarAuthor Commented:
Should I clarify more?
0
 
Roopesh ReddyCommented:
Hi,

OK.

For suppose, if the breakpoint is not hitting, are you getting the result still or not?

Moreover, you can also use IE Developer Tools(F12) or Firebug in Firefox to debug in to this issue!

I see no fault in the code!

Hope it helps u...
0
 
leakim971PluritechnicianCommented:
could you provide a link to your page?
0
 
leakim971PluritechnicianCommented:
Your supposed to return a nice and beautiful JSON object.
If your JSON object is malformed (your return a bit of HTML, unencoded or bad characters) the ajax call will failed.
0
 
Dinesh KumarAuthor Commented:
Hello Experts,

if the break point does not hit it will not make the update in the database which I require.

I am serializing the object to JSON on the service level so json should not be malformed.

 techChallenger1, I am going through the links provided by you.

I think the call to the Handler never fails but to the webservice it some sometimes fails.

why do this happen?
0
 
leakim971PluritechnicianCommented:
in this case send back the error/exception instead and empty object
0
 
Dinesh KumarAuthor Commented:
If there is no syntax error in the following code, does this request everytime will  fetch the data whenever it is called?

$.ajax({
        type: "POST",
        url: "../WebServices/GetForms.asmx/IssuedForms",        
        data: "{FormsIssued:'"+jsonText+"',Remarks:'"+TiRemarks+"',No:'"+qs["No"]+"'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",      
        success: function(msg) {          
                alert("Success");
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {                    
                    return false;
        }
    });

The URL is :  ../WebServices/GetForms.asmx/IssuedForms

But if I use  the following URL ../RecordKeeper/BooksHandler.ashx

it everytime gets data from the server..

first url is webserivce url and another one is handler.

I noticed handler always works but webservice sometimes  failed, what  I did, I added cache: false  in the ajax request then the webserivce started doing well but still I am afraid  of webservice url and more inclined to using Handler.

Please provide your valuable suggestion.
0
 
Dinesh KumarAuthor Commented:
I am using handler url in the following way:

$.get("../RecordKeeper/BooksHandler.ashx",
                {ETO:flag,FormsIssued:jsonText,Remarks:EtoRemarks,Receipt_No:qs["Receipt_No"]},
                function (msg) {          
                //alert("handler" );
                });    
                }
0
 
Dinesh KumarAuthor Commented:
Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 7
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now