zhuanzhou
zhuanzhou

Reputation: 2453

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 output the no match data! tips how should i do

Upvotes: 1

Views: 107

Answers (5)

Rafay
Rafay

Reputation: 31043

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

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

Upvotes: 0

Sam Huggill
Sam Huggill

Reputation: 3126

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.

Upvotes: 0

Coomie
Coomie

Reputation: 4868

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.

Upvotes: 1

TROODON
TROODON

Reputation: 1175

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

Upvotes: 0

Nicolas C.
Nicolas C.

Reputation: 335

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!

Upvotes: 2

Related Questions