1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Why won't my AJAX script work?

Discussion in 'JavaScript' started by Imozeb, Feb 27, 2010.

  1. #1
    Why won't this AJAX script work?
    SEMrush

    Javascript part:

    //get xmlhttp
    xmlhttp = null;
    if (window.XMLHttpRequest)
    {
    // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest();
    }
    else
    {
    // code for IE6, IE5
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    //print
    function print()
    {
    	if (xmlhttp.readyState == 4)
    	{
    		document.getElementById('textbox').innerHTML = xmlhttp.responseText;
    	}
    }
    
    //on submit
    function submit()
    {
    	xmlhttp.open('POST','function.php',true);
    	var text = document.getElementById('textbox').value;
    	var param = text;
    	xmlhttp.send(param);
    	xmlhttp.onreadystatechange = print();
    }
    Code (markup):
    PHP code:

    <?PHP
    $var = $_POST['param'];
    echo $var;
    ?>
    Code (markup):
     
    Imozeb, Feb 27, 2010 IP
    SEMrush
  2. Logic Ali

    Logic Ali Active Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    [QUOTE]xmlhttp.onreadystatechange = print();[/QUOTE]
    Code (markup):
    xmlhttp.onreadystatechange = print;
    Code (markup):
    Except don't call it print because that's already a property of window.
     
    Logic Ali, Mar 2, 2010 IP