How do you simulate jQuery $.get()
to load data from a different domain in jsFiddle?
/* This won't work in jsFiddle. */
$.get("http://www.google.com", function(data) { ... } );
As we know, there is limitation:
Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.
I solved this by creating a Fiddle in jsFiddle just for testing Ajax loads. It’s some very simple HTML with an image and some copy — you can see it here:
Demo on JS Fiddle.
If you use Firebug to click on the “result” frame, you can get the source URL of the iframe. When you copy this source URL into the Fiddle containing your Ajax request, it will work because now it is on the same domain. Here’s a demonstration:
Demo on JS Fiddle.
If you are simply trying to do some examples you can use JSONP and the twitter api for testing purposes. If your server supports JSON requests, then i don't think that there should be any problem.
Just set the data type as JSON as shown below
Does this help?
Check out How can I use the JSFiddle echo feature with JQuery?.
Also check out their API which gives examples to how achieve this.
This simple example should do, try out the fiddle.
You need to create a JSON object wrapping your actual data in a json element.