簡體   English   中英

json_decode不輸出任何內容(試圖從外部php文件獲取json_encode的數據)

[英]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.phpecho 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM