http_request failing between sites

Discussion in 'JavaScript' started by cesarcesar, Aug 4, 2008.

  1. #1
    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);
    
    Code (markup):
    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);
    	
    }
    
    Code (markup):
    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.
     
    cesarcesar, Aug 4, 2008 IP
  2. yleiko

    yleiko Peon

    Messages:
    74
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    sorry, you cantdo that
    browsers wont allow that
    (it would be both a security leak and cause lots of other problems if allowed)
     
    yleiko, Aug 4, 2008 IP
  3. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Instead use CURL. Use AJAX to send XHR to the CURL script on ur server. Now let the CURL script return the responseText by fetching it from remote site!
     
    rohan_shenoy, Aug 5, 2008 IP
  4. cesarcesar

    cesarcesar Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    cesarcesar, Aug 5, 2008 IP