开发者

how to receive the value

the php file:

if (!isset($servers[$ext])){
    die('no match data!');
}
return $output;

the html file:

$.ajax({
    type:"get",
    url:"/tests/api/?u="+u,
    dataType:"json",
    data:"",
    success:function result(data){
        $("#show").html(data);
        $("#show").show();


    }
});

when happens no match data!'. the html file can't output no match data! tips, how to output it, thank you.

there is a response (no match data!)in the firebug console.but the html file can't output it.now, i want to the html file can o开发者_StackOverflowutput the no match data! tips how should i do


why using the "die" function while you just want to echo something as an answer from the server? Remember that when you are using an ajax request, there is not much this request will be able to grab as a response. You'll be able to catch any HTTP response code, its associated text + any text answer.

Simply echo something, json_encode them if you want to have more flexibility in handling multiple values in javascript and that'll do!


Your ajax request is expecting json. In jQuery 1.4 malform json will be rejected.

If you want to return html, set

dataType:"html",

Or set your die statement to return json.


If you die you won't reach the return. @PhpMyCoder

   if (!isset($servers[$ext])){
       $output="no match data!";
    }
    return(json_encode($output));


if (!isset($servers[$ext])){
    return "no match data!";
}


I think you're looking for something like this:

The PHP file:

if (!isset($servers[$ext])){
    $output = 'no match data!';
}
// for good measure, tell the client json is coming back.
header('Content-type: application/json');

echo(json_encode($output));

return;

The JavaScript remains the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜