Search code examples
javascriptzeptotrigger.iohttp-post

Send post request from mobile application built with Trigger.io


Basically the above, I need my mobile application (which is built with Trigger) to send a Post request to a remote server. Specifically, the application generates GPS coordinates and a timestamp and sends the data to a server (which is built with Ruby on Rails), which takes the data and stores it. I'm using the Zepto library to send it. How do I go about achieving this?

<head> <script type="text/javascript" src="/js/lib/zepto.js"></script></head>

$.post(
    url: "http://www.example.com",
    data: {
    latitude: position.coords.latitude;
    longitude: position.coords.longitude;
    timestamp: new Date().getTime();},
    success: alert("Report Successful");
);

This is the code that actually sends the request. I don't believe that the problem lies elsewhere.


Solution

  • Use forge.request.ajax.

    Additionally, there are a couple of problems with your JavaScript code. This snippet should work to do the post (assuming that 'position' is defined earlier in your code):

    forge.request.ajax({
        type: "POST"
        url: "http://yourserver",
        data: {},
        success: function() { alert("Report Successful"); }
    });