Page 3 of 3 FirstFirst 123
Results 31 to 32 of 32

Thread: PHP reloading scripts without reloading the page

  1. #31
    Join Date
    Jan 2005
    Alicante (Spain)
    Quote Originally Posted by Ronnie268 View Post
    Would this work across websites, like say if I my domain were example.com and I had a user who wanted to use it on foo.com, could I tell him to put
    <script type="text/javascript" src="http://example.com/analytics.js"></script>
    in his HTML document?
    No, no decent browser would allow it. When using the XMLHttpRequest object the requested document must be on the parent domain.

  2. #32
    Join Date
    Jan 2007
    XLMHTTPRequest ("proper" AJAX) won't work cross-domain. However, as long as you've got less than a total of 2kb (including hostname and path) of data to submit to the server, you can make asynchronous cross-domain requests by dynamically adding (or modifying) SCRIPT tags, like so:

    HTML Code:
    var args = new Object();
    args.width = 500;     // or whatever ...
    args.height = 300;    // or whatever ...
    // etc. ...
    // turn args into a querystring ...
    var nv_pairs = new Array();
    foreach (var i in args) {
      // you may need/wish to do some URL encoding here as well ...
      nv_pairs.push(i + '=' + args[i]);
    var query_string = nv_pairs.join('&');
    var temp_script = document.createElement('script');
    temp_script.type = 'text/javascript';
    temp_script.src = 'http://yourdomain.com/path/to/script.php?' + query_string;
    You can even have your server-side script (script.php in my example) respond with some JavaScript to respond to a callback function, if necessary.

    HTML Code:
    alert("It worked--hooray!!!");
    My apologies if this type of thing has already been posted in this thread--I admittedly skipped a page of posts ...

    Anywho ... Good luck!
    Jon Wire

    thepointless.com | rounded corner generator

    I agree with Apple. Flash is just terrible.

    Use CODE tags!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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