在您的plovr配置文件中,将警告级别设置为VERBOSE
:
// 配置.js
{
“路径”:“js”,
“模式”:“高级”,
“级别”:“详细”
}
启用警告后,VERBOSE
运行程序会显示以下警告:
JSC_INEXISTENT_PROPERTY:发送的属性从未在 goog.net.XhrIo 上定义...
goog.net.XhrIo.sent('http://remotehost.com:8080/customer/add');
^
尝试更改goog.net.XhrIo.sent();
为goog.net.XhrIo.send();
.
此外,您可能希望将回调函数传递给 XhrIo 发送函数,如下所示:
goog.net.XhrIo.send('http://remotehost.com:8080/customer/add', function(e) {
var xhr = /** @type {goog.net.XhrIo} */ (e.target);
alert(xhr.getResponseText());
});
另一种常见的模式是创建一个 xhr 对象并注册一个事件监听器:
var xhr = new goog.net.XhrIo();
goog.events.listenOnce(xhr, goog.net.EventType.COMPLETE, function(e) {
var xhr = /** @type {goog.net.XhrIo} */ (e.target);
alert(xhr.getResponseText());
xhr.dispose(); // Dispose of the XHR if it is not going to be reused.
});
xhr.send('http://remotehost.com:8080/customer/add');
延伸阅读
闭包:权威指南,第 7 章:客户端-服务器通信