How to get Firebug to tell me what error jquery's .load() is returning?

ⅰ亾dé卋堺 提交于 2019-12-11 07:26:39

问题


I'm trying to find out what data/error jquery's .load() method is returning in the following code (the #content element is blank so I assume there is some kind of error).

  1. Where do I find in Firebug what content or error .load() is returning?
  2. How can I use console.log to find out at least what content is being returned?


(source: deviantsart.com)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript"
        src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("jquery", "1.3.2");
            google.setOnLoadCallback(function() {
                $('#loadButton').click(loadDataFromExernalWebsite);
            });
            function loadDataFromExernalWebsite() {
                console.log("test");
                $('#content').load('http://www.tanguay.info/web/getdata/index.php?url=http://www.tanguay.info/knowsite/data.txt', function() {
       alert('Load was performed.');
    });
            }
        </script>
    </head>
<body>
    <p>Click the button to load content:</p>
    <p id="content"></p>
    <input id="loadButton" type="button" value="load content"/>
</body>
</html>

回答1:


The 'Net' tab of Firebug should show you all HTTP requests (including any from other domains)




回答2:


There is no error. Due to SOO (Same Origin Policy) for XMLHttpRequest, since you are requesting from a remote host (not the same domain as your application). XMLHttpRequest will just return nothing.

But if you modify your .load callback method signature to function(response, status, xhr) {...} the data returned will be in response. But in your case there will be nothing there.




回答3:


I would suggest you to install firequery and you can detect easily jquery problem.




回答4:


Try

$("#content").load("http://www.tanguay.info/web/getdata/index.php?url=http://www.tanguay.info/knowsite/data.txt", function(response, status, xhr) {
  if (status == "error") {
    console.log("Error code :" + xhr.status); // error code
    console.log ("Error text :" + xhr.statusText); // error text
  }
});


来源:https://stackoverflow.com/questions/2734887/how-to-get-firebug-to-tell-me-what-error-jquerys-load-is-returning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!