Solved

AJAX Call Works on LocalHost, doesn't anywhere else

Posted on 2014-02-28
9
1,008 Views
Last Modified: 2014-03-06
I've inherited a website that I'm migrating to a new server (Windows Server 2003 to Windows Server 2012).  Everything seems to work after the migration except one of my ajax calls.  Below is the code that fails:

  var encodedInput = $.toJSON(input);
$.ajax({
        type: "POST",
        url: "Sim.svc/revenue",
        contentType: "application/json; charset=utf-8",
        data: encodedInput,
        dataType: "json",
        error: fnError,
        success: ... 

Open in new window


The sim.svc code is:
<%@ ServiceHost Language="C#" Debug="true" Service="W.Services.Sim" Factory="W.Services.AppServiceHostFactory" %>

Open in new window


W.Services.SIm is a dll.

This ajax call works if I'm on the production server and use http://localhost:80/page.aspx.  However, if I try and access the website (on the production or any where else) using www.domainName/page.aspx the ajax call fails.  

The only thing that indicates that the call has failed is a custom message that says: 'loading failed'.  When I use firebug, it says that sim.svc/renenue is  not found (404)

Any ideas?

Thanks!
0
Comment
Question by:badrhino
  • 8
9 Comments
 
LVL 1

Author Comment

by:badrhino
Comment Utility
I've made a little progress, because I have multiple bindings to this site (e.g. http://domainName.com and http://www.domainName.com) I have to add multipleSiteBindingsEnabled="true"   to the    <serviceHostingEnvironment /> element in the web.config file.

<serviceHostingEnvironment  multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> 

Open in new window


Now,  I'm getting an error that says 'the input string is not in a correct format'.  I get this error if I access it via the domain name or localhost.
0
 
LVL 25

Expert Comment

by:apeter
Comment Utility
Using the developer tools you check the request going in. Check the request is fine.


Had a chance  to look at asp.net web API ? http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
0
 
LVL 1

Author Comment

by:badrhino
Comment Utility
Apeter,

Thanks for the response.  I have hesitated checking the response as I wouldn't think that it would change by simply changing from localhost to domainName.  I will check that now with firebug.  I need to stress that the application workd before I added the multiple bindings element when I used http://localhost:....) but it didn't work if I use www.domainName.com (on production server) .  Once I added the multiple bindings element neither site works, but I don't get an error in the event viewer.

Thanks!
0
 
LVL 1

Author Comment

by:badrhino
Comment Utility
I don't know if this helps, but the response from firebug is:

'InternalServerError'</P><P><B>Details: </B>Input string was not in a correct format.</P><!-- Padding xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:badrhino
Comment Utility
Ok.  I compared the response via a 'compare document' in word (inputs are 2 pages long).  The only difference between the website that is working and the website that is not working is on the website that is not working the LastModified input is:
"LastModified": "/Date(21600000-0600)/"

Open in new window


On the website that is working, the lastModified input is:
/Date(18000000-0500)/

Open in new window


I'm not sure why these are different so I'm going to look into the code....But it looks like it is valid.
0
 
LVL 1

Author Comment

by:badrhino
Comment Utility
This might be the problem.  On the New server, in the response headers it has:
Content-Type:      text/html

In the old server (that works) it has:
Content-Type: application/json; charset=utf-8

any idea's how to fix it?
0
 
LVL 1

Author Comment

by:badrhino
Comment Utility
It looks like the Conet-Type is text/html because the error is being returned as such.  Doesn't look like that is what is causing the problem.
0
 
LVL 1

Accepted Solution

by:
badrhino earned 0 total points
Comment Utility
Finally got it.  It had to do with the fact that I had multiple bindings to the site.  Deleted all but one and everything worked.  Never got the multiple bindings to work, but I really only need one.
0
 
LVL 1

Author Closing Comment

by:badrhino
Comment Utility
Only had one response.  That response while appreciated, didn't help me in solving question.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Today I am discussing AJAX problems in IE7 and I bet this will helps many guys out here who have problems with AJAX work. Lets start with the discovery of problem and then we will talk about its different solutions. My last two projects included …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now