www.webdeveloper.com
Results 1 to 3 of 3

Thread: Simple AJAX dont work. Only make a request one time. :(

  1. #1
    Join Date
    Aug 2006
    Posts
    119

    Simple AJAX dont work. Only make a request one time. :(

    I have a very simple AJAX application for test purpose.
    Her it is:

    one.asp --- the page with ajax function

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    
    <script type="text/javascript">
    var http = GetXmlHttpObject();
    function GetXmlHttpObject()
    { 
    	var objXMLHttp=null
    	if (window.XMLHttpRequest)
    	{
    	objXMLHttp=new XMLHttpRequest()
    	}
    	else if (window.ActiveXObject)
    	{
    	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    	}
    	return objXMLHttp
    }
    
    function getNewContent(value){
    	var url="two.asp";
    	url=url+"?q="+value;
    	url=url+"&sid="+Math.random();
    	http.onreadystatechange = updateNewContent;
    	http.open('GET',url,true);
    	http.send(null);
    
    }
    
    function updateNewContent(){
    	
    	if(http.readyState == 4){
    	document.getElementById('mySentence').innerHTML = http.responseText;
    	}
    }
    
    </script>
    
    </head>
    
    <body>
    <form id="form1" name="form1" method="post" action="">
          
            <select name="udar1" id="udar1" onchange="getNewContent(this.value)">
              <option value='golova'>Golova</option>
              <option value='ruki'>Telo/Ruki</option>
              <option value='nogi'>Nogi</option>
            </select>
    		</form>
    
    
    <div id="mySentence"> </div>
    </body>
    </html>
    Here is the two.asp which makes the desision:

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    
    <%
    if request.QueryString("q")="nogi" then
    	response.write "Nogi"
    else
    	response.write "ne Nogi"
    end if 
    %>
    The problemm is that the page two.asp seems to be called only once, because it does not metter what have been selected from dropdown box, the display value will never change from "Nogi" to "ne Nogi" or otherwise.

    I am stuck with this pritty long. Any help will be appreciated.

  2. #2
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    Always call the open method before assigning a function to the onreadystatechange event handler.
    Code:
    http.open('GET',url,true);
    http.onreadystatechange = updateNewContent;
    Failing to do so requires you to call the abort method between each request -- which would be otherwise unnecessary and extra.
    Last edited by Ultimater; 11-14-2006 at 03:30 PM.

  3. #3
    Join Date
    Aug 2006
    Posts
    119
    OMFG, this example of ajax request was taken from w3schools.com you cannot turst even trusted tutorials (http://www.w3schools.com/ajax/ajax_xmlfile.asp)

    Thank you again Ultimater

Thread Information

Users Browsing this Thread

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

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



Recent Articles