473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

AJAX works locally but not on server

I've put together a simple script that uses the XMLHttpRequest() function. It works when I run it locally, but when I upload it to my web hosting account, I never get a response back. Here is what I have:


[html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html lang="en">
<head>

<script type="text/javascript" language="javascript">
var http_request = false;

function makeRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url + parameters, true);
alert(url);
http_request.setRequestHeader("User-Agent","XMLHttpRequest");
alert('ReadyState ='+http_request.readyState);
http_request.send(null);
alert('sent the request');
alert('ReadyState ='+http_request.readyState);
alert('Status ='+http_request.status);
}

function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById('myspan').innerHTML = result;
} else {
alert('There was a problem connecting with the exchange rate server.');
}
}
}


</script>

</head>

<body>

<br><br>
<input type="button" name="button" value="GET get.php?test=2"
onclick="javascript:makeRequest('http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate', '?FromCurrency=GBP&ToCurrency=USD');">
<br><br>



<br><br>
Server-Response:<br>
<span name="myspan" id="myspan"></span>

</body>
</html>
[/html]

I've thrown in a few alert boxes for debugging, so I could see a few things that are going on. The first "ReadyState" alert box shows different results depending on whether the script is being run locally or remotely. If it is running locally, I get a ReadyState of 1. When uploaded to my hosting account, I get ReadyState=0.

Any ideas about what may be going on here?

Thanks!

Ron
Jul 4 '07 #1
10 2504
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

Could you provide a link to a test page?
Jul 5 '07 #2
Sure. Here's my test page:

http://www.tappingware.com/GetCurrencyRate.html
Jul 5 '07 #3
Ok, I found the issue. It was a cross-domain issue. I didn't know that you can (easily) use AJAX to get data from a third-party source. I set up an application proxy to relay the data, and now everything is working. Thanks!
Jul 6 '07 #4
acoder
16,027 Expert Mod 8TB
Glad you got it working (before I had a chance to look at it!)
Jul 6 '07 #5
briana
3
Ok, I found the issue. It was a cross-domain issue. I didn't know that you can (easily) use AJAX to get data from a third-party source. I set up an application proxy to relay the data, and now everything is working. Thanks!
I'm new at all this and I have been trying to solve this problem for a few days now!
Locally (windows running apache) all is perfect, but on my hosted server (a linux box running apache) the readyState only makes it to 2 (sent).

How did you "set up an application proxy to relay the data"? Sounds like this is something that will solve my problem, but don't quite know what it is or how to instantiate it. Thanks for any help.
Oct 4 '07 #6
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!
How did you "set up an application proxy to relay the data"? Sounds like this is something that will solve my problem, but don't quite know what it is or how to instantiate it. Thanks for any help.
The application proxy is to avoid cross-domain issues. The data is passed to a server-side script which deals with getting the results from a different domain.
Oct 4 '07 #7
briana
3
Welcome to TSDN!

The application proxy is to avoid cross-domain issues. The data is passed to a server-side script which deals with getting the results from a different domain.
I talked to our IT guy and he said that when the ajax call is used Apache (on Linux) is segfaulting. My Apache server (on Windows) doesn't have this problem at all - he's compared our server config files and they are the same.

Has anyone heard of this happening while using asynchronous calls?
thanks for any help.
Oct 23 '07 #8
acoder
16,027 Expert Mod 8TB
I talked to our IT guy and he said that when the ajax call is used Apache (on Linux) is segfaulting. My Apache server (on Windows) doesn't have this problem at all - he's compared our server config files and they are the same.

Has anyone heard of this happening while using asynchronous calls?
thanks for any help.
Can you post some of your code? Can you access the server-side page without Ajax and does it produce the required output?
Oct 23 '07 #9
briana
3
Can you post some of your code? Can you access the server-side page without Ajax and does it produce the required output?

You aren't gonna believe this! It all had to do with how the directory was being written! I'm on windows testing but production server is on linux....I use backslashes for the directory structure and it wanted forward slashes...Plus, I was using php to echo javascript and the file path was getting lost in translation!

Thanks for the speedy responses and bearing with me! Hope this helps someone else at some point.
Oct 23 '07 #10
acoder
16,027 Expert Mod 8TB
You aren't gonna believe this! It all had to do with how the directory was being written! I'm on windows testing but production server is on linux....I use backslashes for the directory structure and it wanted forward slashes...Plus, I was using php to echo javascript and the file path was getting lost in translation!

Thanks for the speedy responses and bearing with me! Hope this helps someone else at some point.
Glad to hear that you got it working and thanks for posting the solution.

Post again anytime if you have more questions.
Oct 24 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: adridder | last post by:
Locally running a "devside" windows apache php mysql server ... everything works perfectly in both firefox and iexplorer now i install it on a remote server ... tried 3 different ones and i...
2
by: nick | last post by:
Hi I have a web form sitting inside a desktop application written in Delphi (rendered by its browser component based on IE engine). The form runs in 2 modes: - live mode: all data freshly...
9
by: schmeckel | last post by:
I am trying to use some very basic AJAX functionality (update panel for partial page update) on my website. When I run my webpage in VS 2005, the partial page update works fine. However, when I...
13
by: adam | last post by:
Hey All, I'm relatively new to all this and any help would be appreciated. What I'm aiming to do is create a few requests, to 1. Search for a Student against XML created from the database 2. If...
1
by: suresh_nsnguys | last post by:
Hi, I will allow users to download one zip file(contain HTML file and 1 image directory with -gif,jpeg files) to his local hard disk. HTML file contain source code to display images ...
3
by: Rob Meade | last post by:
Hi, Up until now I've been developing purely on my local PC, I have AJAX 1.0 installed, and .Net 2.0 - I've just published a project across to the server and its failing, its highlighted the...
8
by: rbrowning1958 | last post by:
Hello, I posted a thread a couple of days back RE using Ajax with JS to read an XML file. This isn't working form me in IE 7 and Vista: xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET",...
5
by: simon | last post by:
hello, I have a server set up on my local (home) network and can not get an ajax application to run on the box. it works fine on our developement server and also works fine locally. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.