0

I'm trying to figure out how to use the URL below to send SMS messages dynamicaly to users who sign up via a form.

In the form I have:

<input type="tel" name="usrtel">

On form submit I want the value of <input name="usrtel"> (e.i. the users mobilnumber) to be inserted into targetNumbers=, in the url below, and then execute that url.

https://admin.intouch.no/smsgateway/sendSms?sender=CompanyName&targetNumbers=12345678&sms=Testmessage&userName=foo&password=bar

Documentation on how to use the SMS service can be found at http://bit.ly/TmQ30D

Can anyone please help me figure out how to figure this out?

This is what I got so far: http://jsfiddle.net/iamchriswick/A8Etr/2/

iamchriswick
  • 380
  • 2
  • 8
  • 24

2 Answers2

1

Here you go..!!

    $.ajax({
      url: 'https://admin.intouch.no/smsgateway/sendSms?sender=CompanyName&targetNumbers=12345678&sms=Testmessage&userName=foo&password=bar',
      type:'GET',
      success: function(res) {
          //do stuff 
       }
   });
Miral Viroja
  • 333
  • 2
  • 10
1

I didn't see your fiddle by the time I posted. Here's mine: http://jsfiddle.net/lsubirana/6tvXQ/

$.ajax({
      url: 'https://admin.intouch.no/smsgateway/sendSms',
        data:{
            'sender':'CompanyName',
            'targetNumbers':$('input[name=usrtel]').val(),
            'sms':'Testmessage',
            'userName':'foo',
            'password':'bar'
            },
      type:'GET',
      beforeSend: function(xhr, settings){
        console.log(settings.url);
        alert(settings.url);
      },
      success: function(res) {

       }

   });

I would use the jQuery ajax method's "data" object to keep your form's data separate from the url in your code... things are a little cleaner that way.

lsubi
  • 116
  • 6
  • Follow up question: The code functions fine in the jsFiddle, but when I try to use it on my server i get a similar error to this. XMLHttpRequest cannot load https://admin.intouch.no/smsgateway/sendSms?sender=CompanyName&targetNumbers=&sms=Testmessage&userName=foo&password=bar. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://domian.com' is therefore not allowed access. Any idea how to get around that? – iamchriswick Jun 06 '14 at 20:22
  • 1
    Your page with the script is not on the same server as admin.intouch.no? This SO question should help: http://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work – lsubi Jun 06 '14 at 20:33
  • Thanks again :) I found the answer in this post: http://bit.ly/1hEggms I just added `crossDomain: true` and `dataType: 'jsonp'`, and so far it seems to be working fine :) – iamchriswick Jun 06 '14 at 20:44