Reputation: 43647
jQuery('input').live('click',function(e){
$.getJSON(
"/json.php",
function(data){
the_name = data.name;
}
);
});
When we press , it should make a json query.
Bit it gives errors.
In Google Chrome console:
In Firefox console:
The strange is when I open http://site.com/json.php, browser gives me a normal json code like:
{"name":"Mary"}
. It is encoded with php json_encode();
What is the problem?
Upvotes: 0
Views: 7641
Reputation: 2183
Load up Firebug and check the request and response using the Console. Make sure the request is getting sent properly and that the response from the server is properly formatted JSON.
Upvotes: 0
Reputation: 6851
maybe your json string is not correct:
try
$.get("/json.php", function(data) {alert(data)});
if you see you data in the alert box try:
$.get("/json.php", function(data) {
var obj = $.parseJSON(data);
alert(obj.name)
});
Upvotes: 1
Reputation: 1038790
Your json.php
script didn't set the Content-Type: application/json
HTTP header?
Upvotes: 0