Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery $.ajax not calling ASP.NET web service method in IE
    text
    copied!<p>I have been trying like the dickens to have a web service called from jQuery using the $.ajax method through IE, but it just does not seem to work. I've looked through Stackoverflow and a veritable amount of Google searches, but none of the solutions people have come up with have worked for me. </p> <p>The following is how things are set up...</p> <p>The jQuery call:</p> <pre><code>function PerformPainPointDataSubmit() { var coordString = ""; var mapAreas = $('map[id$=body_profile_map]').find('area'); mapAreas.each(function() { if ($(this).attr('shape').toLowerCase() == "circle") { coordString += $(this).attr('coords') + ';'; } }); $.ajax({ type: "POST", url: "../../LandingPageWebService.asmx/PerformPainPointDataSubmit", data: JSON.stringify({ "coords": coordString }), //data: "{'coords':'" + coordString + "'}", // Doesn't work //data: '{ "coords": "' + coordString + '" }' // Also doesn't work contentType: "application/json; charset=utf-8", datatype: "json", async: true, cache: false, success: function(data) { alert("success: " + status); }, failure: function(msg) { alert("fail: " + msg); }, error: function(XMLHttpRequest, textStatus, errorThrown) { debugger; } }); //$.delay(1000); &lt;-- Explained a little further down //return false; } </code></pre> <p>Please note that the <code>success</code>, <code>failure</code> and <code>error</code> functions never get called.</p> <p>The following is the definition for <code>LandingPageWebService</code> class (some database code has been removed):</p> <pre><code>[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class LandingPageWebService : System.Web.Services.WebService { [WebMethod(EnableSession=true)] public bool PerformPainPointDataSubmit(string coords) { string hotSpotCoords = string.Empty; string[] coordsSplit = coords.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // parse the string and make sure we only have // values and nothing else. foreach (string spl in coordsSplit) { string[] indCoords = spl.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (indCoords.Length != 3) { return false; } int x = 0; int y = 0; try { x = int.Parse(indCoords[0]); y = int.Parse(indCoords[1]); } catch (FormatException formEx) { return false; } hotSpotCoords += x + "," + y + ";"; } // snipped out Database saving code return true; } </code></pre> <p>The jQuery function is called fron an OnClientClick within a Button:</p> <pre><code>&lt;asp:Button ID="btnSave" Text="Save" runat="server" OnClientClick="PerformPainPointDataSubmit();CloseWin()" CssClass="STD_Button" ValidationGroup="vgEditClinicalSummary" CausesValidation="true" /&gt; </code></pre> <p>The page itself is in a modal dialog that is closed when the 'Save' button is clicked. The web service is called in Chrome and Firefox without any problems, no matter how many times I call it. However with IE it becomes a crap shoot. </p> <p>Typically, but not all the time, it will be called the first time the page is loaded. I figured there was a caching issue, but <code>cache:false</code> was already set. I tried adding a <code>DateTime</code> to the url, but I kept getting errors on that (I honestly don't think I formed it properly, suggestions?). I tried different <code>datatype</code> strings, and of course <code>JSON.stringify()</code> works, but like I said, it will only work once.</p> <p>I noticed while I had a break in the jQuery function that if I waited a second or two, IE would actually make a call to the web service and execute successfully. It would do that every time. I figured the modal window was closing faster than the server could process the request and not make the web service call. I added the <code>$.delay(1000)</code> in the jQuery code hoping it would work, but unfortunately it didn't.</p> <p>Now I am at my wits end and have absolutely no idea how to proceed. Everything seems to make logical sense, but obviously something is amiss. </p> <p>I would be greatly appreciative of help anyone can provide.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload