以前我从控制器向视图发送一个值,并且成功地获得了该值。现在我想使用JSON
数据发送两个值。
控制器
$batch_wise_stock = sprintf('%0.2f',(!empty($pur_product_batch->purchase_qty)?$pur_product_batch->purchase_qty:0)-(!empty($sellt_prod_batch->sale_qty)?$sellt_prod_batch->sale_qty:0));
$batch_wise_rate = $pur_product_batch->rate;
$json_product[] = array('qty'=>$batch_wise_stock,'rate'=>$batch_wise_rate);
echo json_encode($json_product);
** AJAX 技术**
$.ajax( {
url: base_url + "invoice/invoice/batchwise_productprice",
method: 'post',
dataType: "json",
data: {
prod_id: prod_id,
batch_no:batch_no,
csrf_test_name:csrf_test_name,
},
success: function( data ) {
var obj = jQuery.parseJSON(data);
console.log(obj);
if (parseInt(data) >= 0) {
$(".available_quantity_" + sl).val(data.toFixed(2,2));
}else{
var message = "You can Sale maximum " + available_quantity + " Items";
toastr["error"](message);
$("#total_qntt_" + sl).val('');
var quantity = 0;
$("#total_price_" + sl).val(0);
for(var i=0;i<taxnumber;i++){
$("#all_tax"+i+"_" + sl).val(0);
}
}
}
});
错误
Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
1条答案
按热度按时间vmpqdwk31#
尝试遍历返回的数据...(然后与obj进行比较)