store value in database on click of a jquery function by fetching the values from a form

岁酱吖の 提交于 2019-12-11 18:34:05

问题


How to submit a select value on click of a jquery function and save the values in database and return to the same page?

I'm having this select box, This select box is not inside any form.

<select name="myRating" class="rating" id="serialStar">  
   <option value="1">Alright</option>  
   <option value="2">Ok</option>  
   <option value="3">Getting Better</option>  
   <option value="4">Awesome</option> 
   <option value="5">Loved!</option>  
</select>

I'm using below jQuery function to send the select value into a controller action 'set_ratings'

$(document).ready(function(){
$(".ui-rating").click(function(){
    // we want to store the values from the select box, then send via ajax below
    var fid = $('#serialStar').val();
    $.ajax({
        type: "POST",
        url: "http://localhost/reelstubs/movies/set_ratings",
        data: "fid="+ fid
    });
    return false;
});

});

Now I want to save the value into database. How can I achieve this? Is the way proper?


回答1:


the url from ajax must not be relative path from localhost.

instead of

url: "http://localhost/reelstubs/movies/set_ratings"

use

url: "../reelstubs/movies/set_ratings" or where is your php file

The way to add value to database, learn from here: http://www.ibm.com/developerworks/opensource/library/os-php-jquery-ajax/ (this is an example)

good luck



来源:https://stackoverflow.com/questions/11670998/store-value-in-database-on-click-of-a-jquery-function-by-fetching-the-values-fro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!