Based on this answer trying to modify jQuery to send data to PHP and get back in JSON format.
Created this
$.post(
"__02.php",
{
'date_day': date_day,
'currency': currency
},
function (data, textStatus) {
$('#currency_load').html(data);
$('#is_row_changed_currency' + suffix).val(0)
},
"json"
);
PHP is like this
$arr = array ('item1'=>"I love jquery4u",'item2'=>"You love jQuery4u",'item3'=>"We love jQuery4u");
echo json_encode($arr);
But does not work. What need to correct?
For comparison without JSON this works:
$.post("__02.php", { 'date_day': date_day, 'currency': currency }, function(data) {
$('#currency_load').html(data);
$('#is_row_changed_currency' + suffix).val(0)
});
json
is necessary to get following aim
jquery code like
$('#div1').html("<p>item1="+data.item1+"</p>");
$('#div2').html("<p>item2="+data.item2+"</p>");
html
like
<div id="div1"></div>
<div id="div2"></div>
Aim is in certain id
to display corresponding value/element from php array. Without json
does not know how to do it. html
additionally to div
need to use also input
. So in input1
php
array value[0] and so on
Seems function (data, textStatus)
must modify to function (data, success)