473,669 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX works locally but not on server

3 New Member
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="javas cript">
var http_request = false;

function makeRequest(url , parameters) {
http_request = false;
if (window.XMLHttp Request) { // Mozilla, Safari,...
http_request = new XMLHttpRequest( );
if (http_request.o verrideMimeType ) {
// set type accordingly to anticipated content type
//http_request.ov errideMimeType( 'text/xml');
http_request.ov errideMimeType( 'text/html');
}
} else if (window.ActiveX Object) { // IE
try {
http_request = new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try {
http_request = new ActiveXObject(" Microsoft.XMLHT TP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.on readystatechang e = alertContents;
http_request.op en('GET', url + parameters, true);
alert(url);
http_request.se tRequestHeader( "User-Agent","XMLHttp Request");
alert('ReadySta te ='+http_request .readyState);
http_request.se nd(null);
alert('sent the request');
alert('ReadySta te ='+http_request .readyState);
alert('Status ='+http_request .status);
}

function alertContents() {
if (http_request.r eadyState == 4) {
if (http_request.s tatus == 200) {
//alert(http_requ est.responseTex t);
result = http_request.re sponseText;
document.getEle mentById('myspa n').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="javasc ript:makeReques t('http://www.webservicex .net/CurrencyConvert or.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 2545
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

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

http://www.tappingware .com/GetCurrencyRate .html
Jul 5 '07 #3
rbenditt
3 New Member
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 Recognized Expert Moderator MVP
Glad you got it working (before I had a chance to look at it!)
Jul 6 '07 #5
briana
3 New Member
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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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

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

Similar topics

1
1363
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 got the same problem everywhere ....... this is the code that's not executing var fieldNameArray = new Array('aa','ab','ac','ba','bb','bc','ca','cb','cc','da','db','dc','ea','eb','ec','fa','fb','fc','ga','gb','gc','ha','hb','hc','ia','ib','ic' );
2
1797
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 fetched a predefined external server - local mode: users can save the entire html of the web form to a local ..html file and view it at a later time. The problem arises in local mode when the user tries run ajax code from what is effectively a local...
9
1998
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 upload the page to my website and try running it, the page updates as a full page update rather than a partial page update. I believe the web.config I'm using is correct and I have also put the System.Web.Extensions dll in my BIN folder. Can...
13
2141
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 more than one student, list all students using DOM 3. Finally, return individual student and enrolments. Heres the code (sorry it's going to be a long one): request.php
1
1848
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 when user execute the 'HTML' file locally.I will display the images present in the local directory one by one in loop until user close the browser. I want to implement like this If i execute the 'HTML' file locally,first it needs to connect...
3
1321
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 following: sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
8
1409
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", url); where url is a file on my local disk. This works in FireFox, and in
5
3097
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 copied the application to the server, setup the website, installed the ajax extensions, also loaded/enabled front end extensions so i could load the site in visual studio 2005. when i attempt to run the site, either from the server or from another pc...
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.