SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Tutorial or code to retrieve html from a page?

    Basically I'm fetching an rss feed, ripping the data and then I want to use the id passed to retrieve a code from the server.

    http://forums.wuggawoo.co.uk/?section=test

    So basically I want a "display code" link per item that queries the rss site and then displays the html just below the link that was clicked

    I will be distributing this script so other sites can display the codes on theres, so I can't use mootools or jQuery.

    Any help greatly appreciated.

  2. #2
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm okay I found some code on dynamic drive.

    I got it working wen its fetching data off the same server, but from another server I get a

    Code:
    uncaught exception: Permission denied to call method XMLHttpRequest.open
    Error!

    From

    Code:
    //Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)
    //Last updated: Jan 15th, 06'
    
    	function createAjaxObj() {
    		var httprequest = false;
    			if (window.XMLHttpRequest) { // if Mozilla, Safari etc
    				httprequest=new XMLHttpRequest()
    
    				if (httprequest.overrideMimeType)
    					httprequest.overrideMimeType('text/xml');
    			}
    		else if (window.ActiveXObject) { // if IE
    			try {
    				httprequest=new ActiveXObject("Msxml2.XMLHTTP");
    			} catch (e) {
    				try{
    					httprequest=new ActiveXObject("Microsoft.XMLHTTP");
    				} catch (e)
    					{
    					}
    			}
    		}
    		return httprequest
    	}
    	
    	var ajaxpack=new Object();
    	ajaxpack.basedomain = "http://"+window.location.hostname;
    	ajaxpack.ajaxobj = createAjaxObj();
    	ajaxpack.filetype = 'txt';
    	ajaxpack.addrandomnumber = 0; //Set to 1 or 0. See documentation.
    	
    	ajaxpack.getAjaxRequest=function(id) {
    	ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
    
    	if (this.ajaxobj) {
    		this.filetype = 'txt';
    		this.ajaxobj.onreadystatechange = processGetPost;
    		this.id = id;
    		this.ajaxobj.open('GET', 'http://www.myvouchercodes.co.uk/view-code.php?id='+id, true);
    		this.ajaxobj.send(null);
    	}
    	}
    
    	function processGetPost() {
    		
    		id = ajaxpack.id;
    		var myajax=ajaxpack.ajaxobj;
    		var myfiletype=ajaxpack.filetype;
    			
    			if (myajax.readyState == 4) { //if request of file completed
    			if (myajax.status==200 || window.location.href.indexOf('http') == -1) { //if request was successful or running script locally
    				if (myfiletype=="txt") {
    					var validationMessage=document.getElementById("divId_"+id);
    					validationMessage.innerHTML = myajax.responseText;
    				} else {
    					alert(myajax.responseXML);
    				}
    				}
    			}
    		}
    Any tips?

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are getting an error because cross-site ajax is "sort of, kind of prohibited" at the moment.

    Once upon a time you could ajax stuff to/from any domain you liked.
    Then it was decided that it had to be on the same domain that your html came from, or you'd get an error (the error you show). This was a security measure to prevent cross site scripting probably.
    Now - there is talk of opening it up to allow ajax to talk to any server again. I'd google "cross-site ajax" and see if there's anything you can change to open it up.

  4. #4
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found a solution making the javascript query the same server which uses PHP's file_get_contents.

  5. #5
    SitePoint Zealot Ken Sharpe's Avatar
    Join Date
    Apr 2008
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, javascript has been limited for security reasons, definitely not to touch the local machine, and mostly not to touch remote servers either. You can have your server make the request though. For example, PHP has the Curl library (http://us2.php.net/curl) that you could use.

    Word to the wise, though -- use it wisely, stealing other people's content is a great way to get in trouble. You don't want to cause other people any headaches, do you?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •