Answer the question
In order to leave comments, you need to log in
How to pass data from js to php using ajax?
There are dynamically rendered radio buttons
foreach ($offers as $element) {
$offer = $res[$arResult['ID']][$element['ID']];
// echo "<br>Цена ".$element['ITEM_PRICES'][0]['PRINT_PRICE']." ".$res[$arResult['ID']][$element['ID']]['NAME']."<br>";?>
<label for="<? echo "offer_".$offer['ID']?>"><?echo $offer['NAME']." "." - <span>".$element['ITEM_PRICES'][0]['PRINT_PRICE']."</span>"?></label>
<input type="radio" id="<? echo "offer_".$offer['ID']?>" name="offers" value="<?echo $offer['NAME']?>"/><br>
<?}?>
<script>
$(document).ready( function () {
$('input[type=radio]').change(function() {
// console.log(this.value);
var id = this.id.split('_');
var ob = {
'id': id[1]
}
BX.ajax({
url: '/bitrix/templates/adaptive_s1/components/bitrix/catalog/catalog/bitrix/catalog.element/.default/template.php',
type: 'POST',
data:JSON.stringify(ob),
dataType: 'json',
method: 'post',
cache:false,
contentType:"application/json",
onsuccess:function(data){
console.log(data);
}
});
});
});
</script>
Answer the question
In order to leave comments, you need to log in
jQuery.ajax()
Replace
data:JSON.stringify(ob),
data: ob,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question