how to use ajax request in jsFiddle

陌路散爱 提交于 2019-11-28 08:31:23

It's not possible to make an AJAX request to a domain other than the current one, as it's a pretty basic security risk.

jsFiddle have an API for testing AJAX requests which you should use instead.

Here's a working fiddle of what you are probably looking for.

I used http://echo.jsontest.com but you can substitute for your valid URL.

var echo = function(dataPass) {
    $.ajax({
        type: "POST",
        url: "/echo/json/",
        data: dataPass,
        cache: false,
        success: function(json){
            alert("UID=" + json.uid + "\nName=" + json.value);
        }
    });
};

$('.list').live('click', function(){
    $.get("http://echo.jsontest.com/uid/12345/value/nuno_bettencourt", function(data) {
        var json = {
            json: JSON.stringify(data),
            delay: 1
        };
        echo(json);;
    });​ 
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!