JSONP Support

Sterling Hamilton's Avatar

Sterling Hamilton

01 Aug, 2011 05:19 PM via web

http://en.wikipedia.org/wiki/JSONP

This would make it easy to write a jQuery plugin so that people could interact with the API.

UseCase: I am working on a project where I need to take a site and if a mobile client hits the site, it needs to be canonicalized to the mobile URL. In this particular situation, I cannot do this server side, as they are doing heavy caching on the front end using a Proxy. So after the first hit returns a 200 status code it won't run through the server side check again for a pre-determined amount of time (4 hours).

So doing this client side would allow me to still provide the desired functionality.

  1. Support Staff 2 Posted by Aaron Ball on 01 Aug, 2011 06:08 PM

    Aaron Ball's Avatar

    Hi,

    You can use the JavaScript snippet to detect and redirect mobile users client side.

    Does this helps?

  2. Aaron Ball closed this discussion on 01 Aug, 2011 06:08 PM.

  3. Sterling Hamilton re-opened this discussion on 01 Aug, 2011 06:12 PM

  4. 3 Posted by Sterling Hamilton on 01 Aug, 2011 06:12 PM

    Sterling Hamilton's Avatar

    You can use the JavaScript snippet to detect and redirect mobile users client side.

    What snippet?

  5. 4 Posted by Sterling Hamilton on 01 Aug, 2011 06:13 PM

    Sterling Hamilton's Avatar

    Some more context:

    I found out about the API via this:
    http://mode.mofuse.com/

    I don't see snippets on that page. Is there a resource page that I am missing?

  6. Support Staff 5 Posted by Aaron Ball on 01 Aug, 2011 06:16 PM

    Aaron Ball's Avatar

    Hi,

    You can obtain your site specific JavaScript code by going to 'Promote' -> 'Automatic Mobile Detection Code' -> 'JavaScript'.

    Hope this helps.

  7. Aaron Ball closed this discussion on 01 Aug, 2011 06:16 PM.

  8. Sterling Hamilton re-opened this discussion on 01 Aug, 2011 06:21 PM

  9. 6 Posted by Sterling Hamilton on 01 Aug, 2011 06:21 PM

    Sterling Hamilton's Avatar

    You can obtain your site specific JavaScript code by going to 'Promote' -> 'Automatic Mobile Detection Code' -> 'JavaScript'.

    Is this assuming I am a client? I'm not a client - I just found the API.

    I am unable to find "Promote". I'm not trying to be difficult or dense, just trying to find the resource - I figured that would be easier to find on the API page.

  10. 7 Posted by Sterling Hamilton on 01 Aug, 2011 06:23 PM

    Sterling Hamilton's Avatar

    Research:

    The JavaScript redirect code is specific to each mobile site and can be obtained under 'Promote' from the main dashboard. 1. Download the JavaScript Redirect Code from 'Promote' -> 'Automatic Mobile Detection Code' -> 'JavaScript'

    From the API page:

    You do not need to signup to use the service, just get hacking.

    Is this still true or has this changed?

  11. Support Staff 8 Posted by Aaron Ball on 01 Aug, 2011 06:35 PM

    Aaron Ball's Avatar

    I have attached a generic version of the JavaScript snippet but I am also happy to help you get our mobile detection API up and running for you too.

    The attached JS is going to be the easiest route though.

  12. Aaron Ball closed this discussion on 01 Aug, 2011 06:35 PM.

  13. Sterling Hamilton re-opened this discussion on 01 Aug, 2011 06:39 PM

  14. 9 Posted by Sterling Hamilton on 01 Aug, 2011 06:39 PM

    Sterling Hamilton's Avatar

    Thanks Aaron,

    I appreciate you responding quickly!

    Whereas I would think that snippet may help solve the immediate problem, I don't think it's the most scalable solution.

    If we would be able to interface directly with the Mobile Detection API - the information would stay up to date. Using that Javascript snippet you posted means it will eventually be obsolete.

    Could you help me with getting the Mobile Detection API working?

  15. Support Staff 10 Posted by Aaron Ball on 01 Aug, 2011 07:26 PM

    Aaron Ball's Avatar

    No Problem.

    FYI, it will likely not be unusable anytime soon, as there is a 'mobile' catchall and all new devices are using 'mobile' as a differentiator in the user-agent.

    Yeah - let's hack!

    P.S. I am hoping you are a PHP programmer, else I am afraid I might not be much help.

  16. Aaron Ball closed this discussion on 01 Aug, 2011 07:26 PM.

  17. Sterling Hamilton re-opened this discussion on 01 Aug, 2011 08:37 PM

  18. 11 Posted by Sterling Hamilton on 01 Aug, 2011 08:37 PM

    Sterling Hamilton's Avatar

    I am indeed a PHP programmer :)

    Let's hack away.

  19. Support Staff 12 Posted by Aaron Ball on 01 Aug, 2011 08:44 PM

    Aaron Ball's Avatar

    So I forgot you needed to do this on the clients side. Right?

    You can use jquery to get the JSON string too. Something like this:

    $.ajax({ url: url, dataType: 'json', data: data, success: callback });

  20. Aaron Ball closed this discussion on 01 Aug, 2011 08:44 PM.

  21. Sterling Hamilton re-opened this discussion on 01 Aug, 2011 08:55 PM

  22. 13 Posted by Sterling Hamilton on 01 Aug, 2011 08:55 PM

    Sterling Hamilton's Avatar

    I'm using this so far:

    var url = 'http://mode.mofuse.com/api/ver1/?u=' + navigator.userAgent + '&callback=?';

    // Assign handlers immediately after making the request, // and remember the jqxhr object for this request var jqxhr = $.getJSON(url, function() { alert("success"); }) .success(function() { alert("second success"); }) .error(function() { alert("error"); }) .complete(function() { alert("complete"); });

    // perform other work here ...

    // Set another completion function for the request above jqxhr.complete(function(){ alert("second complete"); });

    This won't work because of the Same Origin Policy in place.

    This is why we need JSONP in order to do AJAX requests to your API.

  23. Support Staff 14 Posted by Aaron Ball on 01 Aug, 2011 09:52 PM

    Aaron Ball's Avatar

    OK - you might have me stumped. I will have to spend a little more time on this to get it working and to provide you with a working example.

    Stay tuned.

  24. 15 Posted by Sterling Hamilton on 08 Aug, 2011 09:50 PM

    Sterling Hamilton's Avatar

    Any news on this?

  25. Support Staff 16 Posted by Aaron Ball on 09 Aug, 2011 08:08 PM

    Aaron Ball's Avatar

    Hey Sterling,

    I have not been able to get this to work client side either. I have posted your requested changes to our engineering department and hopeful we can get this working for your soon.

  26. Aaron Ball closed this discussion on 09 Aug, 2011 08:08 PM.

Comments are currently closed for this discussion. You can start a new one.