-1

I have been searching around to find out how to do this but I can't find anything basic enough for my needs.

I want to create a 5 star rating system, that if the 3rd star is clicked for example it passes '3', '$variable1' and '$variable2' to 'rate.php'

I can then create a script in rate.php to insert a query into the correct table etc.

I can do this normally, but not using Ajax. How can I do it using ajax?

5
  • 2
    This has to be one of the most common questions on StackOverflow. Have you really searched for a similar question already or are you fibbing? Commented Sep 23, 2013 at 21:14
  • Please post your code. If you don't have any, you haven't tried hard enough yet. Commented Sep 23, 2013 at 21:15
  • Look THIS or THIS Commented Sep 23, 2013 at 21:16
  • I've used the jQuery Raty plugin (wbotelhos.com/raty) before, it works well with Ajax. Commented Sep 23, 2013 at 21:17
  • possible duplicate of Sending data with AJAX Commented Sep 23, 2013 at 21:33

3 Answers 3

2
       $.ajax({
            url: "rate.php", 
            type: "post", //can be post or get
            data: {star: 3}, 
            success: function(){

            }
        });

In your rate.php you would do this depending on if you did a post or get

$variable1 = $_POST["star"]; //or $_GET["star"]
Sign up to request clarification or add additional context in comments.

Comments

1

Please don't expect much more explanation than this without showing your code, what you've tried and what you've searched.

This shows the general format of how to do it. You will need to get your actual values into the code.

$.post('otherfile.php', {
    stars  : 3, 
    value1 : '$variable1', //whatever this is
    value2 : '$variable2'  //whatever this is
}, function(){
    alert('done');
});

On the PHP Side ...

echo $_POST['stars'];
echo $_POST['value1'];
echo $_POST['value2'];

Comments

0

You listen for an event on your stars, and when they are clicked, you get their value with data() and use $.ajax() to pass that value to your php file of choice. There you get it from the I/O stream or via POST / GET and do whatever...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.