javascript - set attribute value dynamically from from event -
i need set value of attribute show 'x' amount of stars need run event database average , use number?
here html 'data-rateit-value' attribute id modify dynamically.
<div id="randomtest" data-productid="randomtest" class="rateit" data-rateit-value=""></div> i tried modify without event query database , didnt set it? need advise before go on including event.
$('#randomtest').attr( 'data-rateit-value','4'); but once im able able set dynamically have made basic demo of below? if not further guidance appreciated.
$.ajax({ url: 'currentvalue.php', data: { id: productid, value: value }, type: 'post', success: setcurrentvalue }); function setcurrentvalue(data) { $('#randomtest').attr( 'data-rateit-value'.append(data)); } thanks help
edit changed query , results , alerts integer still doesn't append attribute
$.ajax({ url: 'currentstars.php', //your server side script data: { id: productid, value: value }, //our data type: 'post', success: function(results) { alert(results); $('.rateit').attr( 'data-rateit-value'.append(results)) } }); i don't know if helps trying work out why it's not working?
first should check getting expect server:
function setcurrentvalue(data) { console.log(data); ... } what structure of data?
i'm not sure want happen setcurrentvalue function, have syntax errors in line $('#randomtest').attr( 'data-rateit-value'.append(data));. attr can called attr(attribute, value) maybe $('#randomtest').attr( 'data-rateit-value', data); closer need
Comments
Post a Comment