ORION
ORION

Reputation: 2401

$.ajax call returns application/json and works on test server, text/html on production server and fails

Foreword: I know there are many questions similar to this, but none of them have helped me.

I'm in a bit of a bind.

I have an ASP.NET application that uses an $.ajax call to return some data to the page. I have this on 3 different application servers, all of which are Windows Server 2003.

I am NOT running this locally, it is on 3 web application servers. 2 work, 1 doesn't.

This call works flawlessly on the Dev server, the DevTest server, but fails on the production server. I checked the console in Chrome and found that in my Dev and DevTest environments, the ajax call is returning application/json, but on production is returning text/html. Also, on my Dev and DevTest servers, everything works as it should and I get the json returned as it should, but on production, I get a 200 OK, but it returns the entire calling pages html and executes the error function of my ajax call.

Here is my ajax call:

$.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: "RequestDetail.aspx/postAsync",
      data: "{'reqSystem': '" + $('#ctl00_PlaceHolderMain_lblRequestSystem').text() + "', 'vendorNumber': '" + $('#ctl00_PlaceHolderMain_txtVendorNo').val() + "'}",
      dataType: "json",
      success: AjaxSucceeded,
      error: AjaxFailed
      });

Here is the code behind:

<System.Web.Services.WebMethod()> _
Public Shared Function postAsync(ByVal reqSystem As String, ByVal vendorNumber As String) As String
    Dim required = CheckForSpecialApproval(reqSystem, vendorNumber)
    Return required.ToString()
End Function

Here is what I'm seeing in my console in Chrome on production:

Production Chrome Console

And This is what is looks like on Dev:

Dev Chrome Console

I checked the mime types in IIS on my production server and the mime types for javascript and json didn't exist so I had to create them, but it still isn't working. I Googled this to no end and I can't figure out what the problem is.

If you need any other information, I'll gladly provide it.

Please Help.

Thanks in advance.

Upvotes: 2

Views: 1123

Answers (2)

ORION
ORION

Reputation: 2401

Turns out there were missing entries on the production web.config:

<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, &#xD;&#xA;                System.Web.Extensions, Version=3.5.0.0, Culture=neutral, &#xD;&#xA;                PublicKeyToken=31BF3856AD364E35">
  <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, &#xD;&#xA;                System.Web.Extensions, Version=3.5.0.0, Culture=neutral, &#xD;&#xA;                PublicKeyToken=31BF3856AD364E35">
    <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, &#xD;&#xA;                System.Web.Extensions, Version=3.5.0.0, Culture=neutral, &#xD;&#xA;                PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, &#xD;&#xA;                    System.Web.Extensions, Version=3.5.0.0, Culture=neutral, &#xD;&#xA;                    PublicKeyToken=31BF3856AD364E35">
      <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, &#xD;&#xA;                System.Web.Extensions, Version=3.5.0.0, Culture=neutral, &#xD;&#xA;                PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
      <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, &#xD;&#xA;                System.Web.Extensions, Version=3.5.0.0, Culture=neutral, &#xD;&#xA;                PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
      <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, &#xD;&#xA;                System.Web.Extensions, Version=3.5.0.0, Culture=neutral, &#xD;&#xA;                PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
      <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, &#xD;&#xA;                System.Web.Extensions, Version=3.5.0.0, Culture=neutral, &#xD;&#xA;                PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
    </sectionGroup>
  </sectionGroup>
</sectionGroup>

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule,  System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Thanks everyone for your time and answers.

Upvotes: 1

Knaģis
Knaģis

Reputation: 21485

The production responses are all strangely identical in size and much larger than the dev response (173KB against 366B). You should investigate the content of that text/html response - it is very possible that the content is actually an error message formatted in HTML. If Chrome does not give you the ability to view the response, use Fiddler.

Upvotes: 1

Related Questions