I was trying a simple ASP.Net project that calls a web service using AJAX. I just want to try some stuffs I can do with AJAX and JQuery in my desktop. Sort of just diving into the code and expecting that as simple as this would work in 5 minutes. But no, I guess its that kind of a problem that will only happen in your machine and not with others. Thanks to the Download Accelerator Plus installed on my machine I would have not encountered Ajax not passing parameters to the web service. Arrgh!.
Ajax Not Passing Parameters
As you would expect, I got the following components in my ASP.Net project to work on the simple Ajax call test that I want to do.
Web Service
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string CheckIfGalaxyGuardian(string guardian) { var guardians = new[] { "Peter", "Gamora", "Drax", "Groot", "Rocket" }; if (guardians.Any(x => x == guardian)) return "We are Groot!"; else throw new Exception(string.Format("{0} is not a Guardian.", guardian)); }
Asp.Net Page
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>JSON Exception Sample</title> <script src="Scripts/jquery-1.8.2.min.js"></script> <script src="Scripts/Guardian.js"></script> <meta http-equiv="x-ua-compatible" content="IE=9" /> </head> <body> <form id="form1" runat="server"> <div> <input type="button" id="btnSubmit" value="Check Galaxy Guardian"/> <input type="text" id="name"/> </div> </form> </body> </html>
Javascript
$(document).ready(function () { $("input[type=button]").click(function () { var guardian = $("input[type=text]").val(); // Ajax call to service.asmx. $.ajax({ type: 'POST', url: 'GuardianSvc.asmx/CheckIfGalaxyGuardian', data: JSON.stringify({ guardian: guardian }), contentType: "application/json", dataType: 'json', success: function (result) { alert(result.d); }, error: function (result) { var e = JSON.parse(result.responseText); alert(e.Message); } }); }); });
Invalid web service call, missing value for parameter error
When I ran the application I got the error : Invalid web service call, missing value for parameter… Ajax is not passing the parameters to the web service. When you look at the message in fiddler it will show you that no data was passed into the request.
When I tried to use Chrome, it works. So what is wrong with using Internet Explorer?
I tried using the Chrome browser and voila everything is working as expected. I did not do any change in my code. It just works with Chrome. I tried searching about the issue and I got into this Stackoverflow post about IE refusing to send POST data. One of the comments recommended that uninstalling FDM (Free Download Accelerator) fixed the issue for him. I remember having a download manager on my machine so I tried to look a download manager installed and saw that Download Accelerator Plus is installed. My hope is restored.
Disable Download Accelerator Plus or Free Download Manager
Try again with IE
After disabling DAP on my Internet Explorer, I tried running the same web project and now it works.
If you can search Google and hopefully see this post the first time you encountered the same problem, congratulations! I might have saved you couple of hours debugging your program 🙂
Recent Comments