2015-07-21 110 views
-1

我有一個文件graph.php,我在這裏寫php代碼和JavaScript代碼。我用flot來繪製圖表 在傳遞響應時,我使用json_ecode($arr);但我沒有得到任何迴應,並使用相同的圖形消失。

<?php 
    //connected the mysql and after performing some functions got an array 
    echo json_encode($arr); 
?> 
<script src="jquery.js"></script> 
<script> 
    $('#btn'. click(function(){ 
     $.get("graph.php",function(response){},"json") 
    }); 
</script> 

我加header("Content-type :application/json"); 在使用此,瀏覽器下載graph.php,沒有別的來了。

+1

你怎麼知道你沒有得到任何迴應?它看起來像你正在使用一個空的功能,什麼都不做... –

+1

請[參觀],看看周圍,並閱讀[幫助],特別是[*我怎麼問一個好問題?* ](/幫助/如何對問) –

回答

1

嘗試做一些與Ajax響應,或至少檢查它:

$('#btn'. click(function() { 
    $.get("graph.php") 
    .done(function (response) { 
     console.log(response); 
    }) 
    .fail(function (err) { 
     console.log(err); 
    }); 
}); 
0

您可以嘗試測試一些簡單的陣列。不是MySql的結果。

<?php 
$arr = array('action' => 'test', 'data' => 'testing'); 
header("Content-type: application/json"); 
echo json_encode($arr);