Highcharts onclick event break my web service request. Why?
I am new in web development, an开发者_开发问答y help will be greatly appreciated! Please give any idea if your have in my case below.
So this is situation. I have a web application. Web application has ascx page and web service. I put several charts of highcharts (client javascript charting library). And script manager with reference to web service.
So, when the document is ready (i use jquery for it) my javascript function (i called it makeUpdate()) with set timeout inteval 1 sec call another javascript function GetDataWrapper().
GetDataWrapper function is wrapper for web service web method GetData() that return data for charts. You know GetDataWrapper looks like:
function GetDataWrapper()
{
MyNameSpace.WebService.GetData(function (result, userContext, methodName) {
// onSuccess may be do some new requests on something else
}, function (error, userContext, methodName) {
// onFailed alert error message
});
}
Also of course i put any expressions in WebService.GetData method in try/catch.
Now if i start my aplication i'll get some delay and my charts will recieve data one by one because i have async computing data (that why i need setTimeout and call javascript makeUpdate() function several times).
So if i just will wait all my charts will get data, that what i need!
BUT!
My highcharts have method onClick to redirect toother page by 'location.href=....' for each pie area like there: http://jsfiddle.net/ggZ9Z/1/.
So If i click on first pie chart with data, when others still wating for data i'll get GetDataWrapper() onFailed alert error message without any exception in WebService.GetData() (i put breack point in this way)
My question is how it could be happened event and call my function onFailed in GetDataWrapper() without exception in WebService.GetData()?
Any suggestions?
Anyway, thank you for your time!
I had a lot of similar issues myself. I don't have any official documented proof to direct you to but I will detail what I have found out through different tests bellow.
The reason for the call of onFailed callback is that while you try to set the location of browser to another page the current page is being unloaded in which case the browser's native XMLHTTPRequest object aborts all asynchronous requests in progress and sets the status of the response to 0. In this case the javascript proxy class generated by ASP.NET to handle the web service requests invokes the onFailed handler.
My solution for this problem was to create a new proxy base class by modifying the original Sys.Net.WebServiceProxy to handle the status code '0' and call an 'onCanceled' callback instead of 'onFailed'. This solution is inconvenient because each proxy class for each web service would be needed to be generated manually.
Maybe there are better solutions that I am unaware of and I would be glad if somebody has such a solution.
精彩评论