Reputation: 1073
I am looking to use an API from my webpage and currently have a working VB example that works in VBA and was hoping that an equivalent method could be created in Javascript
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
http.Open "POST", "https://api.net.nz/Service.svc", False
http.setProxy 2, "http://proxynz", ""
http.Option(4) = intSslErrorIgnoreFlags
http.Option(6) = False
http.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
http.setRequestHeader "SOAPAction", "urn:WebServices/ISaleService/CreateSale"
http.send (strXML)
Post = http.responsetext
The code that I have been working with is here and I think the issue lies with the http.setProxy line in the VB code.
$.ajax({
type: "POST",
url: "https://api.net.nz/Service.svc",
dataType: 'xml',
contentType: "text/xml; charset=\"utf-8\"",
beforeSend: function (xhr) {
xhr.setRequestHeader('SOAPAction', 'urn:WebServices/ISaleService/CreateSale');
},
data: strXML,
async: false,
success: function (data) {alert(data);},
error: function (xhr, status, error) {$('#results').html(error);alert(error)}
});
With the above code I am getting an error message saying
Error: NETWORK_ERR: XMLHttpRequest Exception 101
Update Still looking for a solution for this. I am hoping that someone knows how to reference a proxy for an $.ajax request.
Upvotes: 2
Views: 3056
Reputation: 61
It is because of the SOP implemented in the browser for ajax.
Here is the reference:
jQuery.ajax fails when url is from different server
Upvotes: 1