I am calling goog.net.XhrIo from within this onclick event
goog.events.listen(invBtn, goog.ui.Component.EventType.ACTION,
function(e) {
goog.net.XhrIo.sent('http://remotehost.com:8080/customer/add');
(update :typo here send instead of sent )
This is the very basic task I want to accomplish but this call doesn't even reach the server. I also tried passing url as goog.Uri , doesn't help. I wonder what is stopping from making this call to the server, I tried both host name and ip address but neither helps. It just does nothing.
Is there any thing I can do to see why this call fails to even reach the server.
Appreciate any help
regards Eddie
In your plovr config file, set the warning level to VERBOSE
:
// config.js { "paths": "js", "mode": "ADVANCED", "level": "VERBOSE" }
With VERBOSE
warnings enabled, running your program shows the following warning:
JSC_INEXISTENT_PROPERTY: Property sent never defined on goog.net.XhrIo ... goog.net.XhrIo.sent('http://remotehost.com:8080/customer/add'); ^
Try changing goog.net.XhrIo.sent();
to goog.net.XhrIo.send();
.
In addition, you may want to pass a callback function to the XhrIo send function as follows:
goog.net.XhrIo.send('http://remotehost.com:8080/customer/add', function(e) {
var xhr = /** @type {goog.net.XhrIo} */ (e.target);
alert(xhr.getResponseText());
});
Another common pattern is to create an xhr object and register an event listener:
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');
Closure: The Definitive Guide, Chapter 7: Client-Server Communication