...

View Full Version : Need help with ajax function



ChaZy
10-08-2008, 04:17 PM
Hello,

The following is my script:

Javascript 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
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($sqlprio, MYSQL_ASSOC))
{
$prioriteit = $priorow['prio'];
}

$sqlprioall = mysql_query("SELECT prio FROM projectregistratieprio");
while($row=mysql_fetch_array($sqlprioall, MYSQL_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

A1ien51
10-09-2008, 03:53 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum