1

Looking to place a button that triggers a simple SMS script on my Tropo account using jQuery and an Ajax get request. The button does not need to open anything, but simply trigger the Tropo script (JS) to send an SMS.

The URL with token given on Tropo is: http://api.tropo.com/1.0/sessions?action=create&token=foo

The about URL when triggered send an SMS saying: "Dinner's ready".

I have a button in html: Dinner

In my HTML I'm linked to an external js:

$("#myButton").click( function(e) { 
  e.preventDefault(); 
  $.get("http://api.tropo.com/1.0/sessions?action=create&token=foo", function( data ) { 
    console.log( data ); 
  }); 
}); 

This does not succeed, and does not fire any console errors. Would love some insight.

Naveed
  • 41,517
  • 32
  • 98
  • 131
Pippin
  • 1,066
  • 7
  • 15

2 Answers2

2

I think you are trying to get data from a cross-domain service, according to same origin policy you can't do so. You can try like this:

$("#myButton").click( function(e) { 
  e.preventDefault(); 
  $.ajax({
    url: 'http://api.tropo.com/1.0/sessions?action=create&token=foo',
    dataType: 'jsonp',
    success: function(data) {
        console.log( data ); 
    }
  });
});
The System Restart
  • 2,873
  • 19
  • 28
  • I tried that with tropo and that works, my callback does NOT seem to get used but at least the text message gets sent out :) – pulkitsinghal Jul 10 '12 at 15:25
  • UPDATE: for those still following, Tropo emailed me back commenting that they had incorrectly mapped the tropo number. – Pippin Aug 01 '12 at 05:17
0

As already mentioned this is probably an issue with getting data from a cross domain service. JSONP would get around this but I am not sure that Tropo's API will work with JSONP. I could not find any mention of it in the docs or user forum. If JSONP does not work then you will need to send a message to the server and use some server-side code to call Tropo's WebAPI to send the SMS message.

Kevin Junghans
  • 17,475
  • 4
  • 45
  • 62