Why doesn't dojo.io.script.get() execute the provided error function when receiving a 404? - dojo

I am trying to use the following to do a cross-domain get:
dojo.io.script.get({
url: myUrl,
callbackParamName: "callback",
preventCache: true,
load: dojo.hitch( this, loadFunction ),
error: dojo.hitch( this, function() {
console.log('Error!!!');
})
});
The load function runs fine, however, when the server returns a 404, the error function does not run. Can anyone tell me why?
EDIT
After some investigation, I found that a timeout and handler could be implemented in the following way:
dojo.io.script.get({
url: myUrl,
callbackParamName: "callback",
timeout: 2000
}).then(function(data){
console.log(data);
}, function(error){
alert(error);
});
This uses functionality provided by the dojo.Deferred object.

When accessing server with script tags (that what dojo.io.script.get does), status code and headers are not available.
You may try some other ways to detect a problem, like using a timeout and analyzing a content of a script. The latter is problematic for JSONP calls (like in your example).

I realize this is old but I thought I'd share a solution in case others, like I had, come across this thread.
dojo.io.script is essentially adding a <script/> to your html page. So you can try this:
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', myUrl);
script.onerror = function() {
debugger
}
script.onload = function() {
debugger
}
document.getElementsByTagName('body')[0].appendChild(script);
That way if the script fails to load the onerror event is called.
*This may not work in every instance but is a good start

Related

Error -32 EPIPE broken pipe

I am doing a post request with ajax that should return a partialview but I always get following error in log:
Connection id "0HL6PHMI6GKUP" communication error.
Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -32 EPIPE broken pipe
When looking at the debug log, I see that it is loading the partialview data but than I get the error.
I can't find anything on the net about the -32 EPIPE error, could someone help me explain what this error means?
Ajax call
$( "#PostForm" ).submit(function( event ) {
//Ajax call
$.ajax({
type: 'POST',
url: "/url/path/CreateBox",
data: {
"id": $("#RackId").val(),
"Name": $("#Name").val()
},
success: function(result){
$("#modal").html(result);
}
});
});
Controller
[HttpPost]
public async Task<IActionResult> CreateBox(int id, string Name)
{
//Get the info of the given ID
Rack rack = await this._rackAccess.GetByIdAsync(id);
if (rack == null)
{
return NotFound();
}
Box box = new Box();
box.Rack = rack;
if (!string.IsNullOrEmpty(Name))
{
box.Name = Name;
var result = await this._boxAccess.InsertAsync(box);
//Returns a list of boxes
return PartialView("Boxes", await this._boxAccess.ToRackListAsync(rack.ID));
}else{
//Returns form again
return PartialView("CreateBox", box);
}
}
Version
Aspnet core: 1.1.0
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0"
"Microsoft.AspNetCore.Hosting": "1.1.0",
Solution can be found on github were I posted the problem aswell:
https://github.com/aspnet/KestrelHttpServer/issues/1978
Answer of halter73 on github:
The "communication error" usually comes in ECONNRESET, EPIPE, and ECANCELED varieties. Which one you get usually just depends on which platform you're running on, but all three generally mean the same thing: that the client closed the connection ungracefully.
I have a theory why this is happening. I think that the page might be getting reloaded mid-xhr causing the xhr to get aborted. This can be fixed by returning false from your jQuery submit callback.
I took all your dependencies and your jQuery snippet and demonstrated how this page reload can cause an EPIPE on linux and an ECANCELED on Windows in a sample repro at https://github.com/halter73/EPIPE. It uses csproj instead of project.json because I don't have an old CLI that supports project.json easily available.
Maybe due to long time processing on server-side,
communication pipe was broken by overtime mechanism.
Wish this is helpful.

SPServices loading but not working

$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
debug: true,
completefunc: function (xData, Status) {
console.log($.fn.jquery);
console.log(xData.responseXML);
console.log(xData.responseXML.xml);
}
});
I am having a problem with SPServices not working on our dev server. It works fine on prod and testing but not on dev for some reason. If I run the code above I get the following in the console.
{readyState: 0, responseXML: undefined, status: 0, statusText: "No Transport"}
I read online this can be a problem with cross domain transfers so I set the following:
$.support.cors = true;
With that I now get the following:
{readyState: 0, responseXML: undefined, status: 0, statusText: "Error: Invalid Argument"}
I think this is because the SPGetCurrentUser call is always just returning an empty string for some reason instead of the user. Has anyone seen this behavior before? What are common things that can cause SPServices to load but not be able to execute calls? Thanks for the help.
So turns out this appears to be a bug with SPServices. It appears that when you use SPServices on a site with a port number for some reason it duplicates the port number and so everything breaks. So as in my example above I did not specify the webURL and so SPServices used the current web but duplicates the port as shown here:
correct url: http://yourserver:123/sites/yoursite
SPServices: http://yourserver:123123/sites/yoursite
To fix this simply specify a site relative webURL as shown in the working code below. Hopefully this saves someone some aggravation.
var site = "/sites/yoursite";
$(document).ready(function () {
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser({
webURL: site
}),
webURL: site,
async: false,
completefunc: function (xData, Status) {
//Do stuff here
}
});
});
Thank you for your post. Actually i got statusText:"Network Error" when i try to get the user groups using jquery in sharepoint. After passing the site url to the site variable like above code. my issue got resolved.

My Parse job seems to work repeat itseself over and over again

Write the server part of the app in Parse server, and the job keeps executing over and over again.
Here is the code:
var cloudRequest = {
"U": "jjj",
"T": "ssss",
"D": "tttt"
};
Parse.Cloud.run('joinUTT', cloudRequest, {
success: function(result) {
console.log("Done with joinUTT");
},
error: function(error) {
console.log("Error after joinUTT");
}
});
Any idea how to make it run just once?
Thanks!
I ran into this problem before - really hard to track down! Here's what has helped me:
In your Cloud Code make sure to explicitly call response.success() and response.error().
If you have no results to return, still define your Cloud Code function with (request, response) and call response.success(""); It is key to include "".
My guess is that in absence of explicit success/error Parse continues to retry until it gets one of these results.

Node.js http response end event?

I was using this piece of code to send some http requests and get data, and it was working fine. I recently updated apache and php to latest versions, as well as node.
And 'close' event stopped firing. I also tried 'end' and 'finish' none of this seems to be working.
I need to know when response is ended so I can start processing data, usually it comes in several chunks. Can you guys help?
var req = http.request(options, function(res) {
res.on('data', function (chunk) {
if(chunk != null && chunk != "") {
dataString += chunk; c
}
});
});
req.on('close', function () {
//tadaa it is finished, so we can process dataString
});
req.write(post_data);
req.end();
Current versions: Apache 2.4, PHP 5.4 node 0.10.9
Maybe there is some particular config settings of Apache that prevents it from closing connection?
P.S. I do not think it is Apache though.. I tried google.com with same result.. pretty strange... Anyone have a working code example? (load big data, and know when it ended)
You should be waiting for the end event of the response, not the request.
e.g.
res.on('end', function () {
// now I can process the data
});

dojo.io.iframe.send does not send a request on second time onwards in dojo 1.8

Example code snippet
this._deferred = dojo.io.iframe.send({
url: "/Some/Servie",
method: "post",
handleAs: 'html',
content: {},
load: function(response, ioArgs){
//DO successfull callback
},
error: function(response, ioArgs){
// DO Failer callback
}
});
Steps
click submit button send a request and successfully got a response
click submit button again...request never send...
Appreciate any help
I can't talk for 1.8, but I am using dojo 1.6 and had a very similar issue that I resolved with the following method:
dojo.io.iframe._currentDfd = null; //insert this line
dojo.io.iframe.send
({...
*verified in Chrome Version 25.0.1364.152 m
Source: http://mail.dojotoolkit.org/pipermail/dojo-interest/2012-May/066109.html
dojo.io.frame.send will only send one request at a time, so if it thinks that the first request is still processing (whether it actually is or not), it won't work on the second call. The trick is to call cancel() on the returned deferred result if one exists, like so:
if (this._deferred) {
this._deferred.cancel();
}
this._deferred = dojo.io.iframe.send({
....
that will cancel the first request and allow the second request to send properly.
For dojo 1.8, dojo.io.iframe is deprecated. dojo.request.iframe is used instead.
And the solution from #Sorry-Im-a-N00b still works:
iframe._currentDfd = null;
iframe.get(url, {
data: sendData,
});