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.

2
  • 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 Commented Dec 5, 2012 at 1: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 Commented Dec 6, 2012 at 2:33

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.