Sending Jquery UI slider values to database

余生颓废 提交于 2019-12-08 13:04:01

问题


I have a ui slider element that I am using to let people rate a product, the purpose is to have this slider along with a button to insert the value into a MySQL table (sort of voting)

my slider looks like

$("#slider-range-max4").slider({
                range: "max",
                min: 1,
                max: 10,
                value: 0,
                slide: function (event, ui) {
                    $("#slider-range-max-amount4").text(ui.value);
                }
            });

            $("#slider-range-max-amount1").text($("#slider-range-max1").slider("value"));

How can I use a button to send the value selected by the user to mysql, do I have to embed the code into a form ?

Thanks


回答1:


use ajax like bellow and send the value to php

$(function() {
$( "#slider-range-max" ).slider({
range: "max",
min: 1,
max: 10,
value: 2,
slide: function( event, ui ) {
$( "#amount" ).val( ui.value );
}
});
$( "#amount" ).val( $( "#slider-range-max" ).slider( "value" ) );

    $.ajax({

        type:"POST",
        url:"your.php",
        data:"vote="+$( "#slider-range-max" ).slider( "value" ),
        success:function(response){
        alert(voted);

       } 

    })
});

In PHP

<?php

$vote="";

if(isset($_POST['vote'])){$vote=$_POST['vote']}

//now do your job with MySql here
?>


来源:https://stackoverflow.com/questions/17096883/sending-jquery-ui-slider-values-to-database

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