Question

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.

Was it helpful?

Solution

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 ); 
    }
  });
});

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top