简体   繁体   中英

Ajax “Failed to load resource”

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?

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)
});

您的json.php脚本未设置Content-Type: application/json HTTP标头?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM