kas*_*ega 20 jquery json jsfiddle
我已经阅读了jsFiddle用户指南,了解他们的JSON echo功能,但没有运气生成一个有效的jsFiddle来使用JQuery回显JSON消息.
如何创建一个jsFiddle来回应他们的指南中的JSON:
data: {
json: JSON.encode({
text: 'some text',
array: [1, 2, 'three'],
object: {
par1: 'another text',
par2: [3, 2, 'one'],
par3: {}
}
}),
delay: 3
}
Run Code Online (Sandbox Code Playgroud)
提供的一个例子是我从未使用过的Mootools.因此,从mootools示例到JQuery的简单转换就足够了.
Baz*_*nga 24
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);
}
});
Run Code Online (Sandbox Code Playgroud)
注意我添加了na additonal资源.. jquery-json
在View上使用FireBug控制台进行演示(无需启动开发人员控制台即可查看返回)
tim*_*sly 13
您也可以使用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);
}
});
Run Code Online (Sandbox Code Playgroud)
像这样的东西:
$.get('/echo/jsonp/', { foo : 'bar', biz : 'buzz' })
.success(function(data){ console.log (data) })
Run Code Online (Sandbox Code Playgroud)
基本上,指向函数的url
一部分,你应该设置.JSFiddle的文档说它也有效,但看起来这个特定的URL现在已经失效了; 但是,使用JSONP服务而不指定回调工作正常.$.ajax
/echo/jsonp/
/echo/json/
归档时间: |
|
查看次数: |
13924 次 |
最近记录: |