2

I'm able to get SOAP response using Magento SOAP API by using PHP code. Now I want it using JavaScript/AJAX request. How can I accomplish this? What steps should I follow prepare my Magento to allow AJAX http API request? I tried with the following code for response:

$.soap({
      url: 'https://www.yourdomain.com/api/soap/?wsdl',
      method: 'login',

      data: {
          username:'xxxxx',
          apiKey:'xxxx'
      },

      success: function (soapResponse) {
          alert("yes!!");
      },
      error: function (SOAPResponse) {
          alert(SOAPResponse.toString());
      }
  });

I get this JavaScript error:

XMLHttpRequest cannot load https://www.yourdomain.com/api/soap/?wsdllogin. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 500.
  • I think the basic question is: How do I send SOAP calls via JavaScript, right? I found a nice answer on stackoverflow here: stackoverflow.com/a/11404133/865443 – Anna Völkl Jun 16 '16 at 11:38
  • exactly! I already resolved it...thanks anyway – Tanjil Jul 1 '16 at 8:50
  • I don't know what's your application purpose or who will use it but you have a security issue doing this. If it's a web application accessible for everyone, they will all know your username and apiKey, they could try to get access to other data / create / modify ... of course it also depends on the role you've set on your API user. – Jonathan Ribas Jun 4 '18 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.