SSL_ERROR_HANDSHAKE_FAILURE_ALERT with JQuery GET request - javascript

There is a server which provides a XML under a certain URL (for example: https://myxmlfile). For this server request is a p12 certificate with password needed which I installed in Firefox and on my machine. If I enter the URL in the webbrowser (https://myxmlfile), the xml will be shown.
Now I try to make a jQuery GET Request from my website (which is just running on my local machine at the moment). In that GET Request I want to get the same XML, but this doesn't work and I get SSL_ERROR_HANDSHAKE_FAILURE_ALERT.
I'm pretty new to certificates. So is it not enough to install the certificate in the browser? Do I have to send the certificate in the GET request or something like that?
This is the request:
$.ajax({
type: "GET",
url: 'https://myxmlfile',
data: 'subscriptionID=0011',
dataType: "xml" ,
async: false,
error: function(xhr, status, error){
console.log('Error: '+ xhr.status+ ' - '+ error);
console.log("error");
},
success: function(xml) {
console.log(xml);
}
});
Thanks for your help.

Related

Posting data at clients side localhost from server

I would like to POST some JSON data at clients side localhost from my Web Application.
I tried using localhost but this refers to the Server Side - Localhost. I also tried to use Javascript instead of PHP but this didn't work as well.
The goal I am trying to achieve is to be able to send some data to the clients localhost where an other desktop application will be listening to a specific port and then do some work (like printing a label) with the given data.
Code I tried:
(I am using XAMPP as a localhost test server)
$.ajax({
type: 'post',
url: 'localhost',
dataType: 'json',
data: 'json',
success: function(json) { ... },
error: function(error) { ... }
});
are you referring to a server and client within a local private network? If so, you can just specify the IP address and port of the client when sending the post request.
Ex:
$.ajax({
type: 'post',
url: '192.168.xxx.xxx:8080',
dataType: 'json',
data: 'json',
success: function(json) { ... },
error: function(error) { ... }
});

Random jquery ajax error readyState=0

I have a web application that uses jQuery ajax to get some data. In this site I also have a Logger that reports to me when an error happens.
Very frequently I get this error on ajax calls:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}
The problem is that this error is randomly and I'm not able to reproduce it. I get this for all ajax scripts. The request is made on same origin and at the server I've defined "Access-Control-Allow-Origin", "*".
All browsers get this error:
Safari 9
Chrome
Internet explore 11
etc...
The jQuery ajax code:
$.ajax({
url: 'MyUrl',
type: 'POST',
dataType: "json",
data: {dataVars},
error: function(response, ajaxOptions, thrownError) {
log.error( 'StringError: ' + ajaxOptions + '\n\nthrownError: ' + JSON.stringify(thrownError) + '\n\nResponse: ' + JSON.stringify(response));
},
success: function(res){
}
});
The request is performed to a servlet. What could be the problem?
From W3schools:
readyState=0
Means that the request isn't sent. (your broswer isn't connected to the targeted server).
It's mean that the socket is not opened : no TCP handshake, so the targeted URL is just not reached...
So check the validity of myUrl (is it a good domain? no cross-origin), and also connectivity of the client (proxy? if myUrl is secured / use an other port, maybe it is just not opened...)
I think the issue might be on server side, if it is random. but especially for myUrl, if you can get the web page anyway...
But the error is strange, if it comes from the same server!
Anyway, I think it is because the connection between your client and the targeted server is unstable, so maybe you can try to inscrease the timeout of the request, or retry it on error (example with recursive loop):
var remainingRetry = 3; //or something else
function handleRequest()
{
$.ajax({
url: 'MyUrl',
type: 'POST',
dataType: "json",
data: {dataVars},
error: function(response, ajaxOptions, thrownError) {
if (remainingRetry)
 {
remainingRetry--;
setTimeout(handleRequest, 1000); //timeout between two tries
}
else log.error( 'StringError: ' + ajaxOptions + '\n\nthrownError: ' + JSON.stringify(thrownError) + '\n\nResponse: ' + JSON.stringify(response));
},
success: function(res){
}
});
}
I had the same issue before and in my case the problem was
that other js function redirecting to another page before my first request has a chance to complete which is practically canceling or killing my request
some thing like
function redirectToAnotherPageFn () {
window.location = "/otherpage.html";
};

Cordova with EWS

The communication with the Exchange server is going with SOAP requests.
When I try to run this code on the mobile device I get a status code of "0".
Any help is appriciated.
Code:
$.ajax(
{
type: "POST",
username:'username',
password: 'password',
url: 'https://outlook.office365.com/EWS/Exchange.asmx',
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success: function(data)
{
hyper.log(data);
},
error: function(jqXHR, ajaxOptions, thrownError)
{
hyper.log('error status: ' + jqXHR.status + ' errorTrown: '+ thrownError);
}
});
Connecting from Cordova to EWS with jQuery did not work out for me. But i found a work arround wich might be usefull for some other people.
As an alternative I build a PHP webservice that handled al the communication with EWS.I didn't use the EWS-php class.
Cordova then called the webservice via jQuery.
I am now able to get and adjust calender events etc.
have you looked at https://stackoverflow.com/a/39152138/5884960 I recently did modify the original library to work with cordova. new npm package is ews-js-api-browser

Ajax request failing?

I am trying to retrieve json data from an api.
It keeps failing, but when I look in the Net tab of Firebug I can see that the GET request executed and returned the correct data. Am I doing something wrong or does anyone have tips on how to debug this?
Edit: Have changed to dataType json and error status code is 0
Thanks
$.ajax({
url: 'http://localhost:55894/api/Test/All',
data: {
format: 'json'
},
error: function () {
alert('Error');
},
dataType: 'jsonp',
success: function (data) {
alert('Ok');
},
type: 'GET'
});
From the info you provided the reason it is failing is because you dont have a cross domain access policy setup. Because you are using different ports to host the website and the API you are running into this issue. You can either setup a crossdomain.xml with the proper security settings or you can move both the API and the webserver to the same port.
Have a look at this for more info: http://en.wikipedia.org/wiki/Same-origin_policy
u can try this way:
$.ajax({
type: 'GET',
url: 'url api here',
beforeSend: function() {
},
success: function(data) {
},
error: function(xhr) { // if error occured
},
complete: function() {
},
dataType: 'json'
});
JSON and JSONP are different. If you are using JSONP, the server side must be prepared to support it. Doesn't look like you are using JSONP.
So just change dataType to 'json', as you are "trying to retrieve json data".

How to send XML request in JavaScript

I have an eye tracker (mirametrix) running as a server in localhost. In order to capture data from this I should send a xml request as given below;
SEND:<GET ID="TIME_TICK_FREQUENCY" />
I have a web-app running as the client and I need to make a request to this server through that. I wrote the following code but it doesn't seem to send the request properly to the server.
var request = $.ajax({
url: "http://127.0.0.1:4242",
type: "GET",
dataType: "xml",
data: {
data:'<GET ID="TIME_TICK_FREQUENCY" />'
},
});
Can someone please help me with this ?
Thanks in advance
$.ajax({
url: ajaxurl,
data: "<root><blah><blah></root>",
type: 'POST',
contentType: "text/xml",
dataType: "text",
success : parse,
error : function (xhr, ajaxOptions, thrownError){
console.log(xhr.status);
console.log(thrownError);
}
});
I think you need to post it.
this is not plain javascript.. looks more like jquery.. also what do you mean with 'properly'. It's kind sending it, but not really? Aside from that, I see the following problems
The url is wrong, and although your browser may handle it, your url should end with a slash.
Your xml is invalid. Needs to start with <?xml version="1.0"?>.
If you accessed this script through a different host than 127.0.0.1., or if the script is running on a different port than 4242, this will not work without CORS headers on the server.

Categories

Resources