Re: php and Ajax problem
| From: | Jim Lucas | Date: | Tue, 29 May 2007 04:36:17 +0000 |
| Subject: | Re: php and Ajax problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255736@lists.php.net to get a copy of this message | ||
Richard Kurth wrote:
I can not figure out way this is not working can somebody help? <html> <head> <title>Untitled</title> <script language="JavaScript"> function createRequestObject() { var req; if(window.XMLHttpRequest){So, if it doesn't find a | (pipe) in the returned page, it won't do anything!// Firefox, Safari, Opera... req = new XMLHttpRequest();} else if(window.ActiveXObject) {// Internet Explorer 5+ req = new ActiveXObject("Microsoft.XMLHTTP");} else {// There is an error creating the object, // just as an old browser is being used. alert('Problem creating the XMLHttpRequest object');} return req; } // Make the XMLHttpRequest object var http = createRequestObject(); function sendRequest(action,arg) { // Open PHP script for requests http.open('get', 'eventaction.php?takeaction='+action+'&uid='+arg); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() {if(http.readyState == 4){ var response = http.responseText; var update = new Array(); if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
</script>
</head>
<body>
<?php $event['deleteevent']='<a
href="javascript:sendRequest(delete,32423434234234234324)">Delete this
event</a>';
echo $event['deleteevent'];
?>
</body>
</html>
this is the 'eventaction.php script yo test if the ajax script works
<?
Does your server allow for short_tags = On ???
if($_GET['takeaction']=="delete"){ $uid=$_GET['uid']; echo $uid;Well, as mentioned above, where is the | (pipe) that your JS code is expecting??? Plus, where is the name of the object that you are wanting to take action upon? Looks like your JS is needing something like this. echo "{$div_id}|{$uid}"; Hope this helps
exit; } ?>