1

I want to make a request http Webservice API to

https://sms.vietguys.biz/api/u=[user]&pwd=[password]&from=[Title]&phone=[phonenumber]&sms=[ContentSMS]

using javascript.

Can I do this on Sharepoint Online ?

When I handle by below code:

var urlstring =`https://sms.vietguys.biz/api/u=[user]&pwd=[password]&from=[Title]&phone=[phonenumber]&sms=[ContentSMS]`;
$.ajax({
    url: urlstring,
    success: function (data) { 
        //do smth with data
    },
    error: function(a,m){
       //process error
    }

I got this error:

XMLHttpRequest cannot load .No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://benhvienthuduc.sharepoint.com' is therefore not allowed access. The response had HTTP status code 404.

  • that error suggests that you need to enable cors for your service, this article should help with that. – garglblarg Oct 5 '16 at 7:48
0

You can use ajax:

$.ajax({
    url: "https://sms.vietguys.biz/api/u=[user]&pwd=[password]&from=[Title]&phone=[phonenumber]&sms=[ContentSMS]",
    success: function (data) { 
        //do smth with data
    },
    error: function(a,m){
       //process error
    }
});
0

The error you are getting is because of security restriction that prevents requests being made from one domain to another ie from xxx.sharepoint.com is requesting sms.vietguys.biz . To overcome this a commonly used practice is CORS and another method is by using JSONP

  • Can you take me a example about CORS, plzz? sms.vietguys.biz is another organization, i can't using JSONP, because i can't code server side. – Văn Trịnh Oct 5 '16 at 8:18
  • But if that api is not configured for cross domain calls then you cannot consume it from another domain – Unnie Oct 5 '16 at 8:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.