如何在JQuery中使用JSFiddle回显功能? [英] How can I use the JSFiddle echo feature with JQuery?

查看:103
本文介绍了如何在JQuery中使用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
}

我从未用过的Mootools中提供了一个示例.因此,从mootools示例到JQuery的简单转换就足够了.

解决方案

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);
    }
});

实时演示

请注意,我已经添加了其他资源.jquery-json

> 在View上使用FireBug控制台进行演示 (无需拉起开发者控制台查看收益)

I have read the jsFiddle user's guide for their JSON echo feature but with no luck of producing a working jsFiddle to echo a JSON message using JQuery.

How can I create a jsFiddle to echo the JSON from their guide:

data: {
    json: JSON.encode({
        text: 'some text',
        array: [1, 2, 'three'],
        object: {
            par1: 'another text',
            par2: [3, 2, 'one'],
            par3: {}
        }
    }),
    delay: 3
}

The one example provided is in Mootools which I've never used. So a simple translation from the mootools example into JQuery would be sufficient.

解决方案

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)

这篇关于如何在JQuery中使用JSFiddle回显功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆