First ajax request not succeeding in Chrome, working in other browsers - javascript

Here is what i am doing.
I have a webpage(with SSL). Call it s1.
It hosts a .js file, which installs a 3rd-party js, used to navigate it. (say s2)
On a click on an element, it loads an iframe(another website, say s2), which in turn passes data to my js hosted on s1.
This is working correctly in IE, Firefox etc, but in Chrome, the first such instance gets cancelled.
When i try again (after the first request is cancelled), it works as expected. (after the first cancellation).
Any ideas on what might be happening. Am not sure how to post a working snippet here as the second iframe is a protected one.
I am guessing something to do with Cross-domain communication, but not sure as it's working in other browsers.
Any ideas on what could be happening.
Thanks

Related

Aborting/Cancelling an AJAX request not working in IE

I have an application where a user is allowed to upload and download documents. In the download area, the user can select multiple files (all pdf), and do a merge and download.
Great.
There is a modal window that pops up during the merge process, that shows the status of the merge, with a progress bar using SignalR. This works fine across all browsers, and the download happens.
Problem: There is a Cancel Merge and Download button on this modal. It stops the SignalR hub, and sends an abort() request to the AJAX call. This works in Safari, Chrome, and FF - but not IE.
When I look at Fiddler, Chrome stops the server side method in it's tracks. In IE, it tries to send that request to SignalR. The result in IE is that the modal window goes away as expected, but a few seconds later you receive the prompt that the file has been downloaded (actual processing never stops). Note the difference where the abort is called in the Fiddler session below.
Fiddler (Chrome - working):
Fiddler (IE - not working):
Javascript:
$('#cancelDownloadMerge').on('click', function () {
$.connection.hub.stop();
XX.Documents.DocumentsView.download.abort();
XX.Documents.DocumentsView.mergeCancelled = true;
XX.Documents.DocumentsView._isMerging = false;
});
The AJAX call that gets fired when Merge And Download is initially clicked is lengthy and proprietary, however, cache: false and crossDomain: true (since currently running localhost) are set as such, yet the problem still persists. I do not think the AJAX call is so much relevant as this is very much isolated to IE, but I can try and post more if needed.
I suspect this has something to do with the fact that Chrome and FF are using ServerSentEvents whereas IE is using forever frame (SSE not supported).
I'm stuck on this one, any help is greatly appreciated.
The problem was due to the fact that SignalR was always defaulting to using Forever Frame in IE. Adding the below restriction forced SignalR to use Long Polling in IE.
$.connection.hub.start({ transport: ['webSockets', 'serverSentEvents', 'longPolling'] });

Replacing entire page via AJAX causes Permission Denied error in IE only

I have an AJAX post that retrieves data from the server and either replaces part of the page or in some cases the full page. This is controlled by a javascript fullRefresh parameter. The problem is the refresh code works find in Firefox but causes a Permission Denied error in the bowels of JQuery after it runs in IE although it would appear to actually replace the page contents successfully.
IE version 11.0.9600.16659
JQuery version 1.8.2
Error message
Unhandled exception at line 2843, column 3 in http://localhost:62761/Scripts/jquery-1.8.2.js
0x800a0046 - JavaScript runtime error: Permission denied
My code is
function RefreshScreenContent(formActionUrl, formHTML, fullRefresh) {
fullRefresh = (typeof fullRefresh === "undefined") ? false : fullRefresh;
if (fullRefresh) {
document.write(formHTML);
document.close();
}
else {
$("#content-parent").html(formHTML);
}
}
The partial refreshes work fine but the full refreshes are the problem. I have tried hardcoding the document.write call to write a well formed simple html page rather than formHTML in case that was somehow the problem but even a simple single word page causes the error.
The actual error occurs a some point later with a callback inside JQuery.
The AJAX post to the server is in the same application i.e. is not a cross domain request. I have seen posts online talking aboue cross domain stuff that is not applicable here.
Can anyone tell me why this is happening and how to stop it? Is there an alternative IE way of replacing the page contents?
Your code is fine (at least at first glance). My guess is that you make the call in such a way, that it is interpreted as cross-domain.
I would suggest checking:
http vs https (most common)
the destination port
the root url
maybe the "destination" page makes some requests of its own, check to be on same domain
The reason why IE may be the only one with the problem is that it has higher security demanding by default that other browsers (check advanced security settings - can't remember where they are put in menu) so it interprets requests in a more "paranoid" manor.
I repeat, what I said is just a guess, based on cases I've been put into.
In the end I used the approach here to replace the body tag in the pgae with the one in the markup the AJAX receives back https://stackoverflow.com/a/7839921/463967
I would have preferred to replace all content not just the body but I can always adapt later to include the header etc as body is enough for my uses right now. This works in IE and Firefox.

javascript failing with permission denied error message

I have a classic ASP web page that used to work... but the network guys have made a lot of changes including moving the app to winodws 2008 server running iis 7.5. We also upgraded to IE 9.
I'm getting a Permission denied error message when I try to click on the following link:
<a href=javascript:window.parent.ElementContent('SearchCriteria','OBJECT=321402.EV806','cmboSearchType','D',false)>
But other links like the following one work just fine:
<a href="javascript:ElementContent('SearchCriteria','OBJECT=321402.EV806', 'cmboSearchType','D',false)">
The difference is that the link that is failing is in an iframe. I noticed on other posts, it makes a difference whether or not the iframe content is coming from another domain.
In my case, it's not. But I am getting data from another server by doing the following...
set objhttp = Server.CreateObject("winhttp.winhttprequest.5.1")
objhttp.open "get", strURL
objhttp.send
and then i change the actual html that i get back ... add some hyperlinks etc. Then i save it to a file on my local server. (saved as *.html files)
Then when my page is loading, i look for the specific html file and load it into the iframe.
I know some group policy options in IE have changed... and i'm looking into those changes. but the fact that one javascript link works makes me wonder whether the problem lies somewhere else...???
any suggestions would be appreciated.
thanks.
You could try with Msxml2.ServerXMLHTTP instead of WinHttp.WinHttpRequest.
See differences between Msxml2.ServerXMLHTTP and WinHttp.WinHttpRequest? for the difference between Msxml2.ServerXMLHTTP.
On this exellent site about ASP you get plenty of codesamples on how to use Msxml2.ServerXMLHTTP which is the most recent of the two:
http://classicasp.aspfaq.com/general/how-do-i-read-the-contents-of-a-remote-web-page.html
About the IE9 issue: connect a pc with an older IE or another browser to test if the browser that is the culprit. Also in IE9 (or better in Firefox/Firebug) use the development tools (F12) and watch the console for errors while the contents of the iFrame load.
Your method to get dynamic pages is not efficient i'm afraid, ASP itself can do that and you could use eg a div instead of an iframe and replace the contents with what you get from the request. I will need to see more code to give better advice.

Under IE8, Page_Init isn't getting called

We've got a site where we Response.Redirect to a page (the cart page) and for some reason, the Page_Init and Page_Load functions aren't being called for that page when using IE8. Even if I put the cursor in the URL Bar and hit enter, they still aren't getting called. When I hit F5, it gets called. When I use another browser (including IE9 in IE8 mode), they get called. I ran Fiddler2 to inspect the traffic and no traffic occurs when I click on the URL bar and hit enter even though you see the world icon spin and it seems to be doing stuff for a 1/2 second.
What could cause this behavior? Seems like it has to be Javascript and/or an Update Panel that's intercepting the Page_Load.
Specifics: The site is an AbleCommerce and the page is the cart page. We've customized the product selection process.
I'm able to replicate the problem on our test instance of the site so I added Breakpoints to both the Page_Init and Page_Load functions of the custom control that loads the cart. Under IE8, I can put my cursor in IE8's url bar and hit enter and the breakpoints never get hit. Any other browser, they get hit. Running IE9 in IE8 Browser Mode, they get hit. But in IE8, they only get hit when I do a refresh (F5).
I'm thinking this has to be a Javascript or Update Panel issue. There are no Javascript errors showing in the Firefox Error console or in IE8.
Any thoughts on what might be causing this? Or how I can troubleshoot it?
Try to call your page with an extra parameter, like &_=xyz where xyz is always fresh (like the current time tostring). If the page is refreshed with an extra parameter, you have a caching issue where the browser caches too aggressively.
Why is could be so - it's hard to say. It could be a jquery issue where you call the url with full caching enabled and then the browser pick up the caching setting internally and never calls back your page.
The current accepted answer is a good way to debug this issue. But a better solution to this issue is that you should set the HTTP headers on the response to tell the browser that it should not cache it.
Take a look at the accepted answer for this Stack Overflow question to learn how to set the cache headers in most popular languages:
Making sure a web page is not cached, across all browsers
I had your exact same problem... It's because the heavy caché options in IE. So instead of using the random variable, I set all response cache to false en every postback like this:
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetNoStore();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
Response.Cache.SetLastModified(DateTime.Now);
Response.Cache.SetAllowResponseInBrowserHistory(false);
....
}
Source: Page_Load called in Firefox, but not IE

jQuery $.get() function succeeds with 200 but returns no content in Firefox

I'm writing my first bit of jQuery, and I'm having a problem with jQuery.get(). I'm calling this;
$.get(url, updateList);
where updateList is defined like so;
function updateList(data)
{
if (data)
{
$('#contentlist').html(data);
}
else
{
$('#contentlist').html('<li>Nothing found. Try again</li>');
}
}
The function runs, and updateList is called. It works fine in Internet Explorer. However, in Firefox, the data parameter is always empty. I would expect it to be filled with the content of the webpage I passed in as the URL. Am I using it wrong?
Notes;
in Firebug, I've enabled the Net panel, and I get the request showing up. I get a 200 OK. The Headers tab looks fine, while the Response and HTML panels are both empty.
The page I'm trying to download is a straight HTML page -- there's no problem with server code.
The page with JavaScript is local to my machine; the page I'm downloading is hosted on the Internet.
I've tried checking the URL by copy-pasting it from my page into the browser -- it happily returns content.
The error occurs even in Firefox Safe Mode -- hopefully that rules out rogue addins.
You probably won't be able to do this due to cross-domain security. Internet Explorer will allow you to Ajax remote domain when running from file://, but Firefox and Chrome won't.
Try to put both files on the same server and see if it works (it should).
You'll most likely need to fix your page that you're quering with XHR because it should be returning content. Copy paste the link in the Firebug net tab and make a new tab, and edit that page with your text editor so it spits content back.
Stick alert (or breakpoint in Firebug) and see if the data returned is not an object (or if there is any data). If the former - you may need to drill into the object to get your markup

Categories

Resources