[英]json_decode outputs nothing (trying to get json_encode'd data from external php file)
在_check_existing_transaction_partners.php
echo '<pre>';
print_r($ajax_existing_company_error);
echo '</pre>';
( 我使用json_encode
对此进行评论。现在仅作为示例显示 )
输出这个
Array
(
[0] => 1
[1] => 2
)
并echo json_encode($ajax_existing_company_error);
输出此["1","2"]
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");
带有alert(data);
弹出1,2
。 到目前为止一切正常。
尝试代替弹出窗口获取其他格式(以处理后者)
尝试$('#json_load').val(data);
和<div id="json_load"></div>
。 什么也看不见
然后尝试$myArray = json_decode($ajax_existing_company_error);
和<?php print_r($myArray); ?>
<?php print_r($myArray); ?>
也什么也没看到。
请建议如何获取$myArray = json_decode($ajax_existing_company_error);
或$('#json_load').val(data);
更新资料
关于json_decode
在_check_existing_transaction_partners.php
是echo json_encode($ajax_existing_company_error);
然后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");
使用查看源代码,看不到与json_decode
相关的json_decode
然后放置<?php print_r(json_decode($ajax_existing_company_error)); ?>
<?php print_r(json_decode($ajax_existing_company_error)); ?>
在关闭</body>
。 也什么也没看到
对于div
,您不使用val()
:使用html()
或text()
$('#json_load').val(data);
应该
$('#json_load').html(data); // or
//$('#json_load').text(data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.