2

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.

Rick
  • 1,063
  • 8
  • 26
  • I presume it's a typo here but you're using different URLs in the two code samples - in the VBA sample `https://api.net.nz/Service.svc` and in the JS sample `https://api.net.nz/SaleService.svc` – barrowc Dec 05 '12 at 01:24
  • Yes, I stripped out the data from each snippet, I have checked my code again and they are both identical URL's. I have also added the error message I am getting from my JS code – Rick Dec 06 '12 at 02:33

1 Answers1

1

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

Community
  • 1
  • 1
leungpeng
  • 61
  • 4