【发布时间】:2012-09-26 02:49:35
【问题描述】:
我正在尝试从一个简单的 java 脚本函数调用我们的 API 服务器。以下是我使用的代码:
function jack() {
//fullURL defined here
debugger;
var xhr = new XMLHttpRequest();
var onLoadHandler = function(event) {
/* do something with the response */
debugger;
}
var onErrorHandler = function(event) {
/* do something with the response */
debugger;
}
xhr.open('GET',fullURL);
xhr.onload = onLoadHandler;
xhr.onerror = onErrorHandler;
xhr.send();
}
我无法加载完整的完整 URL,因为页面显示:“您的帖子包含无效的外部”,因此我可以确认它以 http 开头并转到 /api/phpInfo.php
我打开浏览器访问该页面并启动 Firebug。在 Firebug 控制台中,我调用 jack() 并以 var onErrorHandler = function(event) 结束。 Firebug 告诉我事件是“错误”,但我需要知道什么错误?如果我转到我的 PHP 服务器,我可以在日志中看到调用已完成并返回了服务器 200 代码? Firebug 还显示“HTML”选项卡返回空白,但对 fullURL 的调用确实将信息页面返回给我(在浏览器中)
请帮忙。
【问题讨论】:
-
返回什么? XML? JSON?纯文本?另外,你不使用 jQuery 有什么原因吗?这要容易得多
-
fullURL is myDomain:myPort/api/phpInfo.php Stackoverflow 不希望我粘贴完整的 URL - 非常令人沮丧!