Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with ajax function

    Hello,

    The following is my script:

    Javascript code:
    Code:
    var xmlhttp = false;
    try 
    	{
    		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    	} 
    	catch (e) 
    		{
    			try 
    				{
    					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    				} 
    					catch (E) 
    						{
    							xmlhttp = false;
    						}
    		}
    	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
    		{
    			xmlhttp = new XMLHttpRequest();
    		}
    
    
    function get_prio(id)
    {
    	serverPage = "get_prio.php?id="+id;
    	xmlhttp.open("GET", serverPage);
    	xmlhttp.onreadystatechange = function()
    	{
    		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
    		{
    			var html = xmlhttp.responseText;
    			
    			var json = eval(html); 
    			
    			var elSel = document.getElementById('prio');
    			
    			for(var a = elSel.length -1; a >=1; a--)
    				{
    						elSel.remove(a);
    				}
    			
    			for(var i = 0; i < json.length; i++)
    				{
    					var elOptNew = document.createElement('option');
    					elOptNew.text = json[i].prio;
    					elOptNew.value = json[i].prio;
    					if(json[i].selected == 'selected')
    						{
    								elOptNew.selected = true;
    						}
    					elSel.add(elOptNew, null);
    				}			
    		}
    	}
    	xmlhttp.send(null);
    	
    }

    The php script:
    PHP Code:
    <?php
    include('connect.php');
    require_once(
    'json.php');
    $prioriteit;
    $i 0;
    $result = array();    
    $sqlprio mysql_query("SELECT prio FROM projectregistratie WHERE wo_nr = '".$_GET['id']."'");

    if(
    $priorow=mysql_fetch_array($sqlprioMYSQL_ASSOC))
        {
            
    $prioriteit $priorow['prio'];
        }

    $sqlprioall mysql_query("SELECT prio FROM projectregistratieprio");
    while(
    $row=mysql_fetch_array($sqlprioallMYSQL_ASSOC))
        {
            foreach(
    $row as $prio);
                {
                    
    $result[$i]['prio'] = $row['prio'];
                    if(
    $row['prio'] == $prioriteit)
                        {
                            
    $result[$i]['selected'] = 'selected';
                        }
                }
            
    $i++;
        }

        
    $json = new Services_JSON();
        
    $output $json->encode($result);    
        echo 
    $output;


    ?>
    Now the problem:

    when i execute the code in FF nothing is wrong.
    When i execute the code in IE the readyState = 1

    Can anyone tell me why IE put the readyState on 1 (readyState 1 means that the send() methode is not called)

    Thanks!

    Greetz

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Have you debugged the code and see if the send method is being reached? Have you used a tool like fiddler to see if a request is made?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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