cesarcesar Posted August 4, 2008 Share Posted August 4, 2008 im trying to call a page on "Server B" from "Server A" using http_request method. the problem is the request fails at http_request.open(). Below is the very basic code im using that can be found everywhere online. Code Calling from a page on Server (site) A. Requesting URL is on Server (site) B makeRequest('http://www.sitename.com/ajax_insert.php?field_name=test&field_value=',this.value); This is the code in the makeRequest() function which is on Server (site) A. function makeRequest(url, parameters) { http_request = false; if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } else if (window.XMLHttpRequest) {// Mozilla, Safari,...xmlHttpReq.overrideMimeType http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { // set type accordingly to anticipated content type http_request.overrideMimeType('text/xml'); }else{ alert('Did not create *http_request.overrideMimeType*'); return false; } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = alertContents; // FOR GET VARS http_request.open('GET', url + parameters, true); http_request.send(null); } So what am i missing? How can i get the http_request to process a page on another server (site). FYI, outside this application, my code as written works fine. Thank you much for all the help. Quote Link to comment Share on other sites More sharing options...
corbin Posted August 5, 2008 Share Posted August 5, 2008 Think of the security implications that allowing cross domain AJAX would bring. AJAX is [currently] limited to the domain from which it's being served. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted August 6, 2008 Share Posted August 6, 2008 what you need to do is create a php page that reads data from a remote server and put it in a string then after that you can call the local php script to read data from a remote server. It works like a charm as corbin said you can only read data from the same domain with javascript but php can read remote data Quote Link to comment Share on other sites More sharing options...
cesarcesar Posted August 10, 2008 Author Share Posted August 10, 2008 what you need to do is create a php page that reads data from a remote server and put it in a string Can you expand your suggestion a little. I think i get it, but would like a little more info Quote Link to comment Share on other sites More sharing options...
xtopolis Posted August 10, 2008 Share Posted August 10, 2008 Your ajax calls a local PHP page on your server. On that page you would do the same that you're trying to attempt with Ajax, but have php do it and put the content you're pulling on the screen. Your Ajax takes it from your php page so that you don't violate Ajax security settings. [Local Ajax]->[Local PHP Page/script]->(Remote Page)->[back to Local PHP Page/Script]-[Local Ajax] instead of your: [Local Ajax]--x-->(Remote Page)--x-->[Local Ajax] which isn't allowed. The php script does the fopen, or whatever you need to get data off that remote page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.