JSONP Support
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.
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Aaron Ball on 01 Aug, 2011 06:08 PM
Hi,
You can use the JavaScript snippet to detect and redirect mobile users client side.
Does this helps?
Aaron Ball closed this discussion on 01 Aug, 2011 06:08 PM.
Sterling Hamilton re-opened this discussion on 01 Aug, 2011 06:12 PM
3 Posted by Sterling Hamilton on 01 Aug, 2011 06:12 PM
What snippet?
4 Posted by Sterling Hamilton on 01 Aug, 2011 06:13 PM
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?
Support Staff 5 Posted by Aaron Ball on 01 Aug, 2011 06:16 PM
Hi,
You can obtain your site specific JavaScript code by going to 'Promote' -> 'Automatic Mobile Detection Code' -> 'JavaScript'.
Hope this helps.
Aaron Ball closed this discussion on 01 Aug, 2011 06:16 PM.
Sterling Hamilton re-opened this discussion on 01 Aug, 2011 06:21 PM
6 Posted by Sterling Hamilton on 01 Aug, 2011 06:21 PM
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.
7 Posted by Sterling Hamilton on 01 Aug, 2011 06:23 PM
Research:
From the API page:
Is this still true or has this changed?
Support Staff 8 Posted by Aaron Ball on 01 Aug, 2011 06:35 PM
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.
Aaron Ball closed this discussion on 01 Aug, 2011 06:35 PM.
Sterling Hamilton re-opened this discussion on 01 Aug, 2011 06:39 PM
9 Posted by Sterling Hamilton on 01 Aug, 2011 06:39 PM
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?
Support Staff 10 Posted by Aaron Ball on 01 Aug, 2011 07:26 PM
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.
Aaron Ball closed this discussion on 01 Aug, 2011 07:26 PM.
Sterling Hamilton re-opened this discussion on 01 Aug, 2011 08:37 PM
11 Posted by Sterling Hamilton on 01 Aug, 2011 08:37 PM
I am indeed a PHP programmer :)
Let's hack away.
Support Staff 12 Posted by Aaron Ball on 01 Aug, 2011 08:44 PM
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 });
Aaron Ball closed this discussion on 01 Aug, 2011 08:44 PM.
Sterling Hamilton re-opened this discussion on 01 Aug, 2011 08:55 PM
13 Posted by Sterling Hamilton on 01 Aug, 2011 08:55 PM
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.
Support Staff 14 Posted by Aaron Ball on 01 Aug, 2011 09:52 PM
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.
15 Posted by Sterling Hamilton on 08 Aug, 2011 09:50 PM
Any news on this?
Support Staff 16 Posted by Aaron Ball on 09 Aug, 2011 08:08 PM
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.
Aaron Ball closed this discussion on 09 Aug, 2011 08:08 PM.