javascript - Consume crossdomain WebAPI with Jquery -


i'm trying consume mongolab webapi jquery v1.9 $.ajax this

$.ajax({   url: "https://api.mongolab.com/api/1/databases/my-db/collections/my-coll?apikey=myapikey",   type: "get",   contenttype: "application/json" }); 

and thought crossdomain request, , contenttype should application/javascript , datatype should jsonp, surprisingly, return json result contenttype 'application/json'. i'm quite confuse if jquery encapsulate ajax call , automatically call server application/javascript.

could give me explanation although may looks rookie question?

when try run code in safari jsfiddle.net, get:

failed load resource: origin http://fiddle.jshell.net not allowed access-control-allow-origin.

this means safari asked api.mongolab.com if fiddle.jshell.net allowed access via ajax call, , mongolab.com either did not respond or responded "no, don't allow it". perhaps if domain name localhost or if registered mongolab, allowed execute.

however work in modern browsers. http://en.wikipedia.org/wiki/cross-origin_resource_sharing


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -