+ Reply to Thread
Results 1 to 2 of 2

Thread: help me with ajax

  1. #1
    bioshock's Avatar
    bioshock is offline x10Hosting Member bioshock is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    27

    help me with ajax

    why this javascript doesn't work. Just shows an empty dialog box
    the pkg.html retruns some plain text
    Code:
    function get_data(url)
    {
    var http = new XMLHttpRequest()   ;
    var result = "";
    http.open("GET", url, true);
    http.setRequestHeader("Connection", "close");
    http.onreadystatechange = function() {//Call a function when the state changes.
    
    
    if(http.readyState == 4 || http.readyState == "complete") {
    
    
    result=http.responseText;
    
        }
    }
    http.send(null);
    return result;
    }
      /*]]>*/
      var result = "";
      result=get_data("pkg.html")
      alert(result);
    i am really noob in javascript please help

  2. #2
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: help me with ajax

    You seem to have an odd mix of synchronous and asynchronous code in there, so I have made it all asynchronous:

    Code:
    var xmlhttp = null;
    var result = "";
    
    function get_data(url)
    {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange = rec_data
    xmlhttp.send(null);
    }
    
    function rec_data(){
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    result = xmlhttp.responseText;
    alert(result);
    }
    }
    
    get_data("pkg.html")
    Last edited by lemon-tree; 06-23-2010 at 07:23 AM. Reason: One too many }s

+ Reply to Thread

Similar Threads

  1. ajax help
    By mindstorm8191 in forum Programming Help
    Replies: 2
    Last Post: 07-20-2009, 10:32 AM
  2. Ajax ads
    By xav0989 in forum Feedback and Suggestions
    Replies: 1
    Last Post: 07-14-2009, 11:50 AM
  3. Ajax with Php
    By nyanko in forum Programming Help
    Replies: 4
    Last Post: 09-08-2008, 11:54 PM
  4. Using AJAX to Spy On You
    By subvertman in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 08-15-2005, 08:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers