将Jquery UI滑块值发送到数据库 [英] Sending Jquery UI slider values to database
本文介绍了将Jquery UI滑块值发送到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ui滑块元素,用于让人们对产品进行评分,目的是让该滑块以及将值插入到MySQL表中的按钮(一种投票方式)
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)
我的滑块看起来
$("#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"));
如何使用按钮将用户选择的值发送到mysql,我是否必须将代码嵌入到表单中?
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 ?
谢谢
推荐答案
像波纹管一样使用ajax并将值发送到php
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);
}
})
});
在PHP
<?php
$vote="";
if(isset($_POST['vote'])){$vote=$_POST['vote']}
//now do your job with MySql here
?>
这篇关于将Jquery UI滑块值发送到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文