views:

113

answers:

4

I am using the script found on this page.

I downloaded the whole package found on the page and modified the url to the php file like this:

$('#rate').rating('output.php', {maxvalue:5});

And in the output.php I have this. The author of the page says that the post will be calling rating. So that is why I'm using post rating.

<?php
if(isset($_POST['rating'])) { 
    header("Location: http://www.google.com");
}
?>

But when I run the page and select a few stars nothing happens. The reason why I did header location because I wanted to see if the thing works. But it's not working for me. Do you guys know what I could be doing wrong?

+2  A: 

What do you expect it to do? By doing a header Location of google.com, you are essentially redirecting the AJAX request, not the browser of the user that is making the call. You could just print "test" and check with Firebug that the request was made and the text was returned.

Paolo Bergantino
+2  A: 

Your're sending an ajax request. So you're browser won't redirect. You could use firebug a firefox plugin. You can check you're ajax requests there, and what they return on the console tab.

Plus you're using jquery make sure you're javascript is correct!

MrHus
+1  A: 

As mentioned above, use Firebug's excellent debugging console to check what response you get. The proper way to validate an ajax request is to check if the HTTP_X_REQUESTED_WITH key in the superglobal server array contains XMLHttpRequest. I. e, you could do this:

<?php
function isAjaxRequest(){
  return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
}

if(isAjaxRequest(){
  echo 'Hello, Ajax!';
}
else exit;
?>

Best, Christian

loathsome
something is wrong with this code. i keep getting an error.Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in C:\wamp\www\rating\url.php on line 3tried to fix it but still gives errors.
I'm sorry, I've updated the code now. A small slip is accepted early in the morning, eh? ;-)
loathsome
lol yea, its cool. im having a heat stroak in the morning myself lol.
:( i wonder why nothing is working.
A: 

How do you know nothing is working? Download Firebug, http://getfirebug.net, go to the "NET" tab and do your ajax request. Then check what kind of response you get. You also have to process the data you get from the rating script! You only get the javascript bit, the server side coding is up to you! You could i.e. do a var_dump of the 'RATING' post variable, and debug it with Firebug. Best of luck!

loathsome