JSON显示响应

时间:2013-09-16 00:29:10

标签: javascript php jquery json

我有一个脚本,它抓住了另一个使用PHP制作的JavaScript,它一切正常,但我试图建立一些错误处理,因为有一个问题。目前,如果找不到该文件,错误仍然有效,但如果出现错误,我希望它显示来自PHP代码的消息。我认为使用JSON会起作用,但我对它很新,并承认不知道我在做什么。

如果有人可以帮我解决这个问题,那么目前我还没有收到消息响应消息。

我有以下JQuery代码:

graphURL = 'functions/ICP_summary_graph.php';
graphData = '?ICP=' + ICPSet;
$.ajaxSetup({
    type: 'get',
    URL: graphURL,
    data: graphData,
    success: function (data) {
            var reponse = jQuery.parseJSON(data.response); 
            alert("response :  "+reponse);
            //$('#expconchart').html(data.response);
    },
    error: function(data) {
            $('#meterloader').hide();
            $('#meterbox').html("<div><p class='textcentre bold red'>There was an error loading the chart.</p>");
    } 
});
$.getScript(graphURL + graphData);

和这个PHP:

//GENERATE GRAPH
//SET RESULT ARRAY
$result = array();
//CONNECT TO DATABASE
if(!require('../../connect.php')){
    $result['response'] = "Unable to aquire connection";
    header("content-type: application/json");
    exit(json_encode($result));
} else {
...

任何帮助非常感谢。 :)

0 个答案:

没有答案