Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
php and Ajax problem
Old
  (#1)
Richard Kurth
Guest
 
Posts: n/a
Default php and Ajax problem - 06-02-2007, 08:55 PM

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){
// 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,32423434234234 234324)">Delete this
event</a>';

echo $event['deleteevent'];
?>
</body>
</html>



this is the 'eventaction.php script yo test if the ajax script works
<?
if($_GET['takeaction']=="delete"){
$uid=$_GET['uid'];
echo $uid;
exit;
}


?>

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: [PHP] php and Ajax problem
Old
  (#2)
Stut
Guest
 
Posts: n/a
Default Re: [PHP] php and Ajax problem - 06-02-2007, 08:55 PM

Not even slightly a PHP question, but since it's a bank holiday I seem
to temporarily be in a more helpful mood.

Richard Kurth wrote:
> <?php
> $event['deleteevent']='<a
> href="javascript:sendRequest(delete,32423434234234 234324)">Delete this
> event</a>';
>
> echo $event['deleteevent'];
> ?>


I'm thinking you need some quotes aroung delete, and possibly around the
number given its size.

-Stut
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] php and Ajax problem
Old
  (#3)
Tijnema
Guest
 
Posts: n/a
Default Re: [PHP] php and Ajax problem - 06-02-2007, 08:55 PM

On 5/28/07, Richard Kurth <EMAIL REMOVED> 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){
> // 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,32423434234234 234324)">Delete this
> event</a>';
>
> echo $event['deleteevent'];
> ?>
> </body>
> </html>
>
>
>
> this is the 'eventaction.php script yo test if the ajax script works
> <?
> if($_GET['takeaction']=="delete"){
> $uid=$_GET['uid'];
> echo $uid;
> exit;
> }
>
>
> ?>
>


Try firefox and take a look at the javascript console, it points you
to any javascript syntax errors.

Tijnema
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] php and Ajax problem
Old
  (#4)
Jim Lucas
Guest
 
Posts: n/a
Default Re: [PHP] php and Ajax problem - 06-02-2007, 08:55 PM

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){
> // 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)) {


So, if it doesn't find a | (pipe) in the returned page, it won't do
anything!

> update = response.split('|');
> document.getElementById(update[0]).innerHTML = update[1];
> }
> }
> }
> </script>
> </head>
>
> <body>
> <?php
> $event['deleteevent']='<a
> href="javascript:sendRequest(delete,32423434234234 234324)">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;
> }
>
>
> ?>
>

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] php and Ajax problem
Old
  (#5)
Arpad Ray
Guest
 
Posts: n/a
Default Re: [PHP] php and Ajax problem - 06-02-2007, 08:55 PM

Richard Kurth wrote:
> if(response.indexOf('|' != -1)) {


Spot the misplaced bracket.

> if($_GET['takeaction']=="delete"){
> $uid=$_GET['uid'];
> echo $uid;


This is wide open to XSS attacks, you need to be just as careful with
scripts intended to be accessed via javascript as you do with user
facing scripts. If uid is as it sounds, an integer, then
intval($_GET['uid']) will do nicely; otherwise at least use
htmlentities() to prevent XSS.

Arpad
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top