Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:22:31+00:00 2026-06-15T21:22:31+00:00

Viewing the error box in each process. saveRating.php php code <?php $result = array();

  • 0

Viewing the error box in each process.

saveRating.php php code

<?php
    $result = array();
    $result["status"] = "";
    $result["message"] = "";

    if(isset($_POST["itemID"]) && isset($_POST["itemValue"])){
        $result["status"] = "OK";
        $result["message"] = "Rating has been saved successfully.";
    } else {
        $result["status"] = "ERROR";
        $result["message"] = "Provide itemID and itemValue!";
    } 

    echo json_encode($result);
?>

html code

<body>
    <h1>Creating Five Stars Rating System</h1>
    <div class="fieldRow">
        <label>Book 123A</label>
        <ul id="book-123a" class="ratingStars">
            <li></li>
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <div class="fieldRow">
        <label>Book 123B</label>
        <ul id="book-123b" class="ratingStars">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <div class="fieldRow">
        <label>Book 123C</label>
        <ul id="book-123c" class="ratingStars">
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li class="active"></li>
        </ul>
    </div>

    <div id="placeHolder"></div>
</body>

jquery code

<script>
$(document).ready(function(){
    $('ul.ratingStars li.active').prevAll().addClass('active');

    $('ul.ratingStars li').each(function(){
        var $item = $(this);
        var $itemContainer = $item.parents('ul.ratingStars');
        var containerID = $itemContainer.attr('id');
        var $itemsAll = $itemContainer.find('li');

        $item.mouseover(function(){
            $itemsAll.addClass('default');
            $item.prevAll().addClass('highlighted');
        }).mouseout(function(){
            $itemsAll.removeClass('default').removeClass('highlighted');
        }).bind('click', function(){
            var itemIndex = $itemsAll.index(this);

            $.post('ajax/saveRating.php',{
                'itemID': containerID,
                'itemValue': itemIndex
            }, function(data) {
                if(data && data.status == "100"){
                    $item.addClass('active').removeClass('highlighted');
                    $item.nextAll().removeClass('active');
                    $item.prevAll().addClass('active');
                } else {
                    alert('Error!');
                } 
            }, "json");
        });
    });
});
</script>

css code

<style>
    label, ul {
        float:left;
    }
    .fieldRow {
        clear:both; margin:5px 0px; overflow:hidden;
    }
    ul.ratingStars {
        list-style:none; margin:0px 0px; 
        overflow:hidden;
    }
    ul.ratingStars li {
        float:left; width:16px; height:16px; 
        background:url('icons/star.gif') no-repeat left top; 
        cursor:pointer;
    }
    ul.ratingStars li.active {
        background-position: 0px -32px;
    }
    ul.ratingStars li.default {
        background-position: 0px 0px;
    }
    ul.ratingStars li.highlighted, ul.ratingStars li:hover {
        background-position: 0px -16px;
    }
</style>

stars img file

http://www.packtpub.com/sites/default/files/Article-Images/3081_02_06.png

Always alert('Error!'); Please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:22:32+00:00Added an answer on June 15, 2026 at 9:22 pm

    In your jquery code you check

    if(data && data.status == "100") {
    

    but in your saveRating.php php code you set status as either

    $result["status"] = "OK";
    

    or

    $result["status"] = "ERROR";
    

    hence your javascript check is false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find the root cause of the error message when viewing my
I keep getting the Keyword not supported: 'file access retry timeout' error when viewing
When viewing lots of webpages' source code (like JS,CSS,HTML), I find them in one
While viewing jQuery's uncompressed source code I stumbled upon something I don't quite understand.
I'm viewing variables using the debugger. In debug builds everything in the code below
I am having the following error viewing validation error in Firefox, it works in
When viewing the click in firebug, the call turns red (i.e. error) but I
I'm experiencing an intermittent error. We have a page which, when viewing source in
I am viewing code that I have found from here . When I open
I'm fairly new to rails and I am viewing some other's code. I notice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.