Solved

AJAX Call Works on LocalHost, doesn't anywhere else

Posted on 2014-02-28
9
1,027 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
ID: 39896277
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
ID: 39897145
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
ID: 39897208
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
ID: 39897219
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:badrhino
ID: 39897240
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
ID: 39897270
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
ID: 39897337
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
ID: 39897596
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
ID: 39908834
Only had one response.  That response while appreciated, didn't help me in solving question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 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

11 Experts available now in Live!

Get 1:1 Help Now