简体   繁体   中英

json_decode outputs nothing (trying to get json_encode'd data from external php file)

In _check_existing_transaction_partners.php

echo '<pre>';
print_r($ajax_existing_company_error);
echo '</pre>';

( using json_encode I comment this. Now show only as example )

outputs this

Array
(
    [0] => 1
    [1] => 2
)

and echo json_encode($ajax_existing_company_error);

outputs this ["1","2"]

Jquery code to send data to external file and receive back

var checkbox_to_update = $("#checkbox_to_update").val();
$.post("_check_existing_transaction_partners.php", { 'checkbox_to_update': checkbox_to_update }, function(data, success) {
alert(data);
}, "json");

With alert(data); get popup with 1,2 . So far all OK.


Trying instead of popup get some other format (to process latter)

Tried $('#json_load').val(data); and <div id="json_load"></div> . See nothing

Then tried $myArray = json_decode($ajax_existing_company_error); and <?php print_r($myArray); ?> <?php print_r($myArray); ?> Also see nothing.

Please advice how to get $myArray = json_decode($ajax_existing_company_error); or $('#json_load').val(data);

Update

Regarding json_decode In _check_existing_transaction_partners.php is echo json_encode($ajax_existing_company_error);

Then jquery

var checkbox_to_update = $("#checkbox_to_update").val();
$.post("_check_existing_transaction_partners.php", { 'checkbox_to_update': checkbox_to_update }, function(data, success) {
<?php print_r(json_decode($ajax_existing_company_error)); ?>
}, "json");

With View source see nothing related with json_decode

Then placed <?php print_r(json_decode($ajax_existing_company_error)); ?> <?php print_r(json_decode($ajax_existing_company_error)); ?> just before closing </body> . Also see nothing

For a div , you don't use val() : you use html() or text()

$('#json_load').val(data); 

should be

$('#json_load').html(data);  // or
//$('#json_load').text(data); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM