JQuery $.get in IE and Edge not firing - javascript

In our web application we want to trigger a locally run widget using xhttp request, in Chrome and firefox, this is working fine and the requests are being received but in MS browsers (Edge and IE11) it wort fire and I get an error returned to the variable,
The request line is;
var screenRecorder = $.get('http://127.0.0.1:9645/widget?command=connect&agent=amtest&password=amtest');
where agentName and password are taken from JS variables
[object,object] {readystate:1}
I am relying on the correct response being received to flag if the widget is running to allow further communication requests to it.
I am hosting the app on IIS6.1 and have enabled CORS but this still isn't helping with IE and Edge. Can anyone advise how I can resolve this?
The IE console shows the following error:
XMLHttpRequest: Network Error 0x2efd, Could not complete the operation
due to error 00002efd.

The fix for this issue is to initiate a connection before sending the request using the following code before sending the initial and subsequent $.get requests;
var screenRec = new XMLHttpRequest('http://127.0.0.1:9645/widget');
This forces IE and Egde to open the connection as without it the $.get request will not be sent.

Related

Beacon API Cannot load <url> due to access control checks when navigating to new page

I have a navigation.sendBeacon request being sent during a pagehide event on Safari with some analytics data to an endpoint on the same domain as the current page. This works fine when the tab is being closed, but when navigating to a new url, Safari throws Beacon API Cannot load <url> due to access control checks while trying to make the request.
This issue does not occur on Chrome, and there are no other logs shown. I don't think this is a CORS request, all domains and subdomains are the same.
Has anyone else seen this or know how to fix?
Using any sort of Asynchronous HTTP request, whether it is sendBeacon, fetch, or XMLHttpRequest seems to have problems in both desktop and iOS Safari at the moment when inside a pagehide event. I have received versions of the same error such as Fetch API cannot load ... due to access control checks when I use different types of HTTP requesters within the pagehide event. I am sure that it is not a CORS error, since the exact same request does not have a problem outside of a pagehide event.
While not recommended due the its blocking of the main thread, I am using synchronous requests until the bug is patched in Safari. For my use case, it is more critical that the analytics data from pagehide is successfully sent even even though it causes a small delay to the end user. Synchronous HTTP requests are a meh workaround until the bug is remediated, which hopefully is soon since the link from #Phillip Walton suggests that a patch has been accepted but obviously has not been released yet.
if (isSafari && pageHideBroken) {
$.ajax({
type: "POST",
async: false, //The most important line
url: `https://`,
data: 'Goodbye',
timeout: 5000
});
}
else {
navigator.sendBeacon(`https://`, 'Goodbye');
}
I have confirmed that on both Desktop Safari and iOS Safari that my backend successfully receives the data using this approach. JQuery is not required to make a sync HTTP request, but I just used $.ajax as the example due to its conciseness compared to XMLHttpRequest. If you make this workaround conditional like I have, then it is easy to swap back to navigator.sendBeacon once the bug is fixed! This type of browser-dependent behavior is never fun to code around.

xhr status value 12019 in IE

I am sending an AJAX request in an app running on IE.
Sometimes xhr return with an error whose status value is 10219
It seems like its not a standard HTTP status code and might be IE specific.
What could be the reasons for this error and how to fix this ?
I am using IE11.
PS: I tried googling for this but could not found anything useful. Also this is an silverlight applicatoin

Ajax chat program errors when retrieving messages [duplicate]

I keep receiving this error when I do some Ajax calls...
It may even be something to do with Geocoding but I really have no idea how to capture the error to display something useful to users... or even how to solve the problem as it seems to just be referencing some kind of pointer or something :S 0x2ef3
SCRIPT7002: XMLHttpRequest: Network Error 0x2ef3, Could not complete the operation due to error 00002ef3.
An image might be more helpful than the error message:
Any ideas at all?
My code fires off 10 ajax calls in 1 second to be processed by geocoding server side.
The error comes up intermittently. Sometimes I get geocoded results and sometimes I get that error. I would say I get it 10% of the time. It completely stops the ajax call from firing my error handler in jQuery.
This is the fix that worked for me. There is invalid mime or bad characterset being sent with your json data causing that errror. Add the charset like this to help it from getting confused:
$.ajax({
url:url,
type:"POST",
data:data,
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(){
...
}
});
Reference:
Jquery - How to make $.post() use contentType=application/json?
Could not complete the operation due to error c00ce56e
We also encountered similar problems. However, setting the charset as noted in the previous comment did not help. Our application was making an AJAX request every 60 seconds and our webserver, nginx, was sending Keep-Alive timeout at 60 seconds.
We fixed the problem by setting the keep-alive timeout value to 75 seconds.
This is what we believe was happening:
IE makes an AJAX request every 60 seconds, setting Keep-Alive in the request.
At the same time, nginx knows that the Keep-Alive timeout value is ignored by IE, so it starts the TCP connection close process (in the case of FF/Chrome this is started by the client)
IE receives the close connection request for the previously sent request. Since this is not expected by IE, it throws an error and aborts.
nginx still seems to be responding to the request even though the connection is closed.
A Wireshark TCP dump would provide more clarity, our problem is fixed and we do not wish to spend more time on it.
I received the same error (SCRIPT7002: XMLHttpRequest: Network Error 0x80004004, Operation aborted), in our case it was because of JavaScript's same origin policy.
Our web app was making a JQuery AJAX call to our server on Port 8080. The call was getting intercepted and re-routed over SSL (due to server rules mandating that incoming traffic use SSL).
Once we made our web app load through the SSL port the issue was fixed.
I had this problem, a an AJAX Post request that returned some JSON would fail, eventually returning abort, with the:
SCRIPT7002: XMLHttpRequest: Network Error 0x2ef3
error in the console. On other browsers (Chrome, Firefox, Safari) the exact same AJAX request was fine.
Tracked my issue down - investigation revealed that the response was missing the status code. In this case it should have been 500 internal error. This was being generated as part of a C# web application using service stack that requires an error code to be explicitly set.
IE seemed to leave the connection open to the server, eventually it timed out and it 'aborted' the request; despite receiving the content and other headers.
Perhaps there is an issue with how IE is handling the headers in posts.
Updating the web application to correctly return the status code fixed the issue.
Hope this helps someone!
This issue happened in my project because of an ajax GET call with a long xml string as a parameter value. Solved by the following approach:
Making it as ajax post call to Java Spring MVC controller class method like this.
$.ajax({
url: "controller_Method_Name.html?variable_name="+variable_value,
type: "POST",
data:{
"xmlMetaData": xmlMetaData // This variable contains a long xml string
},
success: function(response)
{
console.log(response);
}
});
Inside Spring MVC Controller class method:
#RequestMapping(value="/controller_Method_Name")
public void controller_Method_Name(#RequestParam("xmlMetaData") String metaDataXML, HttpServletRequest request)
{
System.out.println(metaDataXML);
}
I had this error for some time and found a fix. This fix is for Asp.net application, Strange it failed only in IE non compatibility mode, but works in Firefox and Crome. Giving access to the webservice service folder for all/specific users solved the issue.
Add the following code in web.config file:
<location path="YourWebserviceFolder">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
I have stumbled across this questions and answers after receiving the aforementioned error in IE11 when trying to upload files using XMLHttpRequest:
var reqObj = new XMLHttpRequest();
//event Handler
reqObj.upload.addEventListener("progress", uploadProgress, false);
reqObj.addEventListener("load", uploadComplete, false);
reqObj.addEventListener("error", uploadFailed, false);
reqObj.addEventListener("abort", uploadCanceled, false);
//open the object and set method of call (post), url to call, isAsynchronous(true)
reqObj.open("POST", $rootUrlService.rootUrl + "Controller/UploadFiles", true);
//set Content-Type at request header.for file upload it's value must be multipart/form-data
reqObj.setRequestHeader("Content-Type", "multipart/form-data");
//Set header properties : file name and project milestone id
reqObj.setRequestHeader('X-File-Name', name);
// send the file
// this is the line where the error occurs
reqObj.send(fileToUpload);
Removing the line reqObj.setRequestHeader("Content-Type", "multipart/form-data"); fixed the problem.
Note: this error is shown very differently in other browsers. I.e. Chrome shows something similar to a connection reset which is similar to what Fiddler reports (an empty response due to sudden connection close).
Also, this error appeared only when upload was done from a machine different from WebServer (no problems on localhost).
I just want to add what solved this problem for me, as it is different to all of the above answers.
The ajax calls that were causing the problem were trying to pass an empty data object. It seems IE does not like this, but other browsers don't mind.
To fix it I simply removed data: {}, from the ajax call.
With the Apache 2 change KeepAliveTimeout set it to 60 or above
Upping the directive in the virtualhost for KeepAliveTimeout to 60 solved this for me.
Have encountered the same issue in my asp.net project, in the end i found the issue is with the target function not static, the issue fixed after I put the keyword static.
[WebMethod]
public static List<string> getRawData()
Incase none of these solutions were "clear" enough, essentially IE/Edge is failing to parse your "data" field of your AJAX call properly. More than likely you're sending an "encoded" JSON object.
What Failed:
"data": "{\"Key\":\"Value\"}",
What Works:
"data":'{"Key":"Value"}'
[SOLVED]
I only observed this error today, for me the Error code was different though.
SCRIPT7002: XMLHttpRequest: Network Error 0x2efd, Could not complete
the operation due to error 00002efd.
It was occurring randomly and not all the time. but what it noticed is, if it comes for subsequent ajax calls. so i put some delay of 5 seconds between the ajax calls and it resolved.

XMLHttpRequest missing body for PATCH in IE9

I'm trying to call an API using the PATCH http method from IE9, every time the XMLHttpRequest is sent it drops the actual request body. The actual request is coming from an AngularJS application. Angular just uses the native xhr under the covers in it's $http service. I've verified the behavior is not Angular-specific running the snippet below in the IE console and inspecting the network traffic - no body gets sent with the request
var request = new XMLHttpRequest();
request.open('PATCH', '/api/v1/fake/404/', false);
request.setRequestHeader("Content-type","application/json");
request.send('{"isActive": 1}');
if you change PATCH to PUT or POST it sends the json request body just fine. Is PATCH just not supported in IE9 XHR? Is there any workaround?
After doing a bunch of research. it appears that there really isn't any workaround. PATCH http requests just aren't supported in IE9.

IE11 returns status 0 during Ajax POST operation from an iFrame (XMLHttpRequest: Network Error 0x2ee4)

It seems that IE11 version 11.0.7 (KB2929437 on Win7, KB2919355 on Win 8.1) has a problem when performing an Ajax POST operation. The operation returns status 0 and on an F12 console, the following error appears:
SCRIPT7002: XMLHttpRequest: Network Error 0x2ee4, Could not complete the operation due to error 00002ee4.
The conditions to reproduce this issue are as follows:
Happens only on specific IE11, i.e. version 11.0.7 (KB2929437 on
Win7, KB2919355 on Win 8.1)
iframe is used to load external page with https protocol (parent page is using http protocol)
ajax with method 'POST' is used
More frequently happens with Connection: Keep-Alive header set on by IIS
More frequently happens on Win32 version of IE11
I created the following jsfiddle to reproduce this issue: http://jsfiddle.net/VJ2D6/12/
$(document).ready(function () {
$('#frame').attr('src', 'https://54.249.142.247/ie11/test.html');
});
Please note that the iframe retrieves its source from another site 54.249.142.247 (hosted by EC2 node using IIS7), because jsfiddle doesn't host https.
And, because I am using Self-Sign SSL Certificate, please first install the certificate to the Trusted Root, and turn off "Warn about certificate address mismatch" from Internet Options - Advanced Tab.
Inside 54.249.142.247/ie11/test.html, I created a button which initiates an Ajax POST operation to a non-existing location. Normally this request should return status 404 error (Not found). But in case of IE11 version 11.0.7, it often returns status 0 error and shows Network Error 0x2ee4 inside F12 console, "
I posted the same issue to Microsoft Connect here: https://connect.microsoft.com/IE/feedback/details/877525/ie11-returns-status-0-during-ajax-post-operation-from-an-iframe-xmlhttprequest-network-error-0x2ee4#tabs
I think this is an IE11 bug, but I am not 100% sure and there is no confirmation yet from the IE team. Please help me to confirm whether this is an IE bug, or if there is any problem in my JavaScript code.
UPDATE:
Microsoft said that they can reproduce the problem and will investigate it.
This error is be cause a ssl certificate is invalid. For solve this error see: [Link]
$.get(window.api + 'Values', null, null).done(function () {//solution for IE shit
$.ajax({
type: 'POST',
url: https://api.yourdomain.com,
data: yourData,
success: function (data) {
//do something
},
});
});
I was having the same issue when trying to do a POST call to our HTTPS WCF service (CORS) and looks like it's because of the SSL Certificate.
I had to recreate mine with the following MakeCert Command line
makecert.exe -r -pe -n "CN=*.YourDomain.com" -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -a sha256 -sy 12 "C:\EncryptionCert.cer"
installed the created Cert into Client and server trusted root cert Auth.
After choosing this cert for my Site binding, I was able to successfully call my HTTPS WCF service in IE 11.
I have the same issue too. at first i use make a get request before post. it solve the issue. but when i deep in, i find it's the in the internet option -》 Advanced options
cancel check for server certificate revocation*
cancel check for publisher certificate revocation*
click ok
restart your browser
i resolved the issue
enter image description here

Categories