user2465936
user2465936

Reputation: 1040

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); ?> 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)); ?> just before closing </body>. Also see nothing

Upvotes: 0

Views: 254

Answers (1)

Hanky Panky
Hanky Panky

Reputation: 46900

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); 

Upvotes: 1

Related Questions