Solved

AJAX Call Works on LocalHost, doesn't anywhere else

Posted on 2014-02-28
9
1,051 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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