Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net 4 jQuery Ajax not working with page method in iis
    text
    copied!<p>Im normally an MVC chap, so jquery ajax is usually a breeze. Im working on an old webforms project though and cannot get jquery ajax to talk to a webmethod on my local iis. It works on visual studios own web server though.</p> <p>The jquery is:</p> <pre><code>//Collect data var prefs = { 'pref_1': $('input#pref_1').val(), 'pref_2': $('input#pref_2').val(), 'pref_3': $('input#pref_3').val(), 'pref_4': $('input#pref_4').val() } //Send data via ajax //Uncomment below to send requests var loc = window.location.href; var substr = loc.split("?"); $.ajax({ url: substr[0] + "/SetUserPreferences", type: "POST", data: JSON.stringify(prefs), dataType: "json", contentType: "application/json; charset=utf-8" }); </code></pre> <p>As you can see I'm taking the location href and searching for the method in there. <br/> In the index.aspx page I have:</p> <pre><code>[WebMethod] public static void SetUserPreferences(string pref_1, string pref_2, string pref_3, string pref_4) { using (lbDataContext dc = new lbDataContext()) { MoreBang_Preference preference = new MoreBang_Preference(); preference.UserId = (int)HttpContext.Current.Session["UserId"]; preference.DateSubmitted = DateTime.Now; preference.Preference1 = pref_1; preference.Preference2 = pref_2; preference.Preference3 = pref_3; preference.Preference4 = pref_4; dc.MoreBang_Preferences.InsertOnSubmit(preference); dc.SubmitChanges(); } } </code></pre> <p><br/></p> <p>The site I am working on is an umbraco site, it has</p> <pre><code>&lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt; </code></pre> <p>in the httpModules section of the web config and is running in Asp.Net 4 integrated mode. <br/> It also has <br/> <code>&lt;add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;</code> <br/> in the modules tag of the system.webServer section of the web config. <br/> I am genuinly stumped as to why it isnt working. <br/></p> <p>Many thanks in advance to those who contribute!</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