简体   繁体   English

json_decode不输出任何内容(试图从外部php文件获取json_encode的数据)

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

In _check_existing_transaction_partners.php _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 ) 我使用json_encode对此进行评论。现在仅作为示例显示

outputs this 输出这个

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

and echo json_encode($ajax_existing_company_error); echo json_encode($ajax_existing_company_error);

outputs this ["1","2"] 输出此["1","2"]

Jquery code to send data to external file and receive back jQuery代码将数据发送到外部文件并接收回来

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); 带有alert(data); get popup with 1,2 . 弹出1,2 So far all OK. 到目前为止一切正常。


Trying instead of popup get some other format (to process latter) 尝试代替弹出窗口获取其他格式(以处理后者)

Tried $('#json_load').val(data); 尝试$('#json_load').val(data); and <div id="json_load"></div> . <div id="json_load"></div> See nothing 什么也看不见

Then tried $myArray = json_decode($ajax_existing_company_error); 然后尝试$myArray = json_decode($ajax_existing_company_error); and <?php print_r($myArray); ?> <?php print_r($myArray); ?> <?php print_r($myArray); ?> Also see nothing. <?php print_r($myArray); ?>也什么也没看到。

Please advice how to get $myArray = json_decode($ajax_existing_company_error); 请建议如何获取$myArray = json_decode($ajax_existing_company_error); or $('#json_load').val(data); $('#json_load').val(data);

Update 更新资料

Regarding json_decode In _check_existing_transaction_partners.php is echo json_encode($ajax_existing_company_error); 关于json_decode_check_existing_transaction_partners.phpecho json_encode($ajax_existing_company_error);

Then jquery 然后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 使用查看源代码,看不到与json_decode相关的json_decode

Then placed <?php print_r(json_decode($ajax_existing_company_error)); ?> 然后放置<?php print_r(json_decode($ajax_existing_company_error)); ?> <?php print_r(json_decode($ajax_existing_company_error)); ?> just before closing </body> . <?php print_r(json_decode($ajax_existing_company_error)); ?>在关闭</body> Also see nothing 也什么也没看到

For a div , you don't use val() : you use html() or text() 对于div ,您不使用val() :使用html()text()

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

should be 应该

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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