Ajax Not Passing Parameters Using Internet Explorer – Solved

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.

Fiddler Request Message  Before DAP

Fiddler Response Message  Before DAP

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

Download Accelerator Plus  Disable IE Integration

Try again with IE

After disabling DAP on my Internet Explorer, I tried running the same web project and now it works.

Fiddler Response  Ajax working in IE

Not A Guardian

Galaxy Guardian

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 :)

 

How To Transfer App.Config ApplicationSettings to Web.config

Add Web Reference from a class library for .Net 2.0

If you still use .Net framework 2.0, the way to reference a web service to your project is to add a Web Reference.
What if you want to add the web reference from a class library project? This will result to Visual Studio automatically
adding an app.config to your project. The app.config will contain the configuration under applicationSettings of the newly added reference of the web service.

Add Web Reference - ApplicationSettings

Add Web Reference

The app.config will look like this for example.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Noel.Sample.ServiceInterface.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Noel.Sample.ServiceInterface.Properties.Settings>
<setting name="Noel_Sample_ServiceInterface_ServiceHello_Service"
serializeAs="String">
<value>http://localhost:59962/Service.asmx</value>
</setting>
</Noel.Sample.ServiceInterface.Properties.Settings>
</applicationSettings>
</configuration>

What if you want to use one config file?

Your main application is a web application and it has its own web.config file. What if you want to use and maintain one
config file? You don’t need to point the app.config section from your web.config file. You can move the section group and
the section of the web service from your app.config to your web.config.

Move app.config applicationSettings to Web.config

<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Noel.Sample.ServiceInterface.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Noel.Sample.ServiceInterface.Properties.Settings>
<setting name="Noel_Sample_ServiceInterface_ServiceHello_Service"
serializeAs="String">
<value>http://localhost:59962/Service.asmx</value>
</setting>
</Noel.Sample.ServiceInterface.Properties.Settings>
</applicationSettings>
</configuration>

The section group can be added to the configSections. The applicationSettings can be added under the configuration section of the web.config.

Get value of service URL from Web.Config under applicationSettings

Under appSettings of a Web.config file usually you use for example ConfigurationManager.AppSettings["WebServiceURL"] to get a value in the Web.config. But when the URL is under the applicationSettings in a Web.config this is how you can get the value of the URL.

public class ConfigHelper
{
public string GetUrl()
{
var section = (ClientSettingsSection)ConfigurationManager.
GetSection("applicationSettings/Noel.Sample.ServiceInterface.Properties.Settings");
var url = section.Settings.Get("Noel_Sample_ServiceInterface_ServiceHello_Service").Value.ValueXml.InnerText;
return url;
}

}

The last step is to remove the app.config from the class library. This is the case if the app.config was added to have the configuration of the web reference. In other cases where you need to the app.config, just remove the configSections and applicationSettings for the web service.

I spent some time looking for a way to make this work and not too much resource from web points to this approach. Hopefully it can help solving yours in less time. Thank you for this post from Stackoverflow on how solve this problem.

Comparing using CompareTo C# Method

CsharpCompareTo.PNG

  A colleague asked me for a suggestion on the program module he is doing that involves determining if one value is ">" greater than, "=" equal or "<" less than another value. I first thought of a solution involving a stack but its too … [Continue reading]

Changing My DNS Provider to DNSimple – What DNS Record?

DNS-DNSimpleDomainAddTransfer.png

  Problem with my current DNS provider - GoDaddy.com I made a blog post two years ago on how I setup this site File -> New Blog Project. As of this writing, this site is using Wordpress and GoDaddy.com for web hosting and DNS. Lately, I … [Continue reading]

Notepad++ – Source Code Editor and More

SyntaxHighlighting.PNG

  Using Notepad++ with Visual Studio To compliment Visual Studio, I use Notepad++ as my other source code editor. Visual Studio is still my primary IDE but its good to have Notepad++ on the side for that quick search in files, syntax … [Continue reading]

LocalDb – SQL Express for Developers

VSSqlExpressConnectoin.PNG

  When you install Visual Studio 2012 or higher the Sql Server Express component is also installed on your machine. When you add a connection to a database within VS I normally use .\SQLEXPRESS as the server name. The .\SQLEXPRESS … [Continue reading]