json - How can I use the JSFiddle echo feature with JQuery?

ID : 274384

viewed : 24

Tags : jqueryjsonjsfiddlejquery





Top 4 Answer for json - How can I use the JSFiddle echo feature with JQuery?

vote vote

91

var data = {         json: $.toJSON({             text: 'some text',             array: [1, 2, 'three'],             object: {                 par1: 'another text',                 par2: [3, 2, 'one'],                 par3: {}             }         }),         delay: 3 }   $.ajax({     url:"/echo/json/",     data:data,     type:"POST",     success:function(response)     {        console.log(response);     } }); 

Live Demo

Note I have added na additonal resource.. jquery-json

Demo with FireBug Console on View (no need to pull up developer console to see return)

vote vote

85

You can also use JSON.stringify

$.ajax({   url:"/echo/json/",   data:{     json: JSON.stringify({         text: 'some text',         array: [1, 2, 'three'],         object: {             par1: 'another text',             par2: [3, 2, 'one'],             par3: {}         }       }),     delay: 3   },   type:"POST",   success:function(response) {     console.log(response);   } }); 

‚Äč

vote vote

77

Something like this:

$.get('/echo/jsonp/', { foo : 'bar', biz : 'buzz' })     .success(function(data){ console.log (data) }) 

JS Fiddle example.

Basically, point the url portion of your $.ajax function at /echo/jsonp/ and you should be set. JSFiddle's docs say that /echo/json/ works, too, but it looks like that particular URL is down at the moment; using the JSONP service without specifying a callback works just fine, though.

vote vote

70

Top 3 video Explaining json - How can I use the JSFiddle echo feature with JQuery?







Related QUESTION?