I have following API with Javscript API for fast2sms.com:
function sendOtp() {
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.fast2sms.com/dev/bulkV2",
"method": "POST",
"headers": {
"authorization": "APICodeOfMyAccount",
"Content-Type":"application/json",
"accept": "*/*",
"cache-control": "no-cache",
},
"data": {
"route": "v3",
"sender_id" : "TXTIND",
"language" : "english",
'flash':0,
"message": 'Abccompany.com: '+Math.floor(100000 + Math.random() * 900000)+' is your OTP.' ,
"numbers": $('#sendOtpForm input[name="mobileNumber"]').val()
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
I have called sendOtp function on button click, but it does not work. If I used API using PHP according to API documentation Fast2sms.com, then sms is sent successfully.
But, if I use API wih Javascript, then CORS Policy error is displayed:
Why Php works so easily and Javscript API is causing too much trouble? Any help will be highly appreciated.
I gave a try with GET method. GET method is working fine. POST method is not working. I will go with GET method now