Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use ajax request in jsFiddle

I'm trying to create my first fiddle. So here's what I want to do with jquery

$('.list').live('click', function(){
    var dataPass = 'uid='+ uid;
    $.ajax({
        type: "POST",
        url: "test.php",
        data: dataPass,
        cache: false,
        success: function(html){
            //Do something
        }
    });
});

So how/where do I write the codes for test.php file? It's going to return some html markup.

like image 806
ptamzz Avatar asked Sep 10 '11 19:09

ptamzz


People also ask

How do I use JSFiddle?

Entering and running code JSFiddle has the notion of panels (or tabs if you switch into the tabbed layout), there are 4 panels, 3 where you can enter code, and 1 to see the result. Once you enter code, just hit Run in the top actions bar, and the fourth panel with results will appear.

Does JSFiddle support jQuery?

You can select jQuery, and other extensions and frameworks, from the Frameworks & Extensions drop down. Also, depending on the library selected there are also some other extensions to that library. An example below of jQuery 1.7. 2, you can also include jQuery UI, jQuery Mobile etc.

How do you write JSFiddle code?

You can write your functions in VS Code and then copy & paste into the JavaScript console. Or you can try out JSFiddle, a useful tool for experimenting with JavaScript. With JSFiddle, you can write code in the JavaScript box and then execute it by clicking the Run button on the menu bar at the top of the JSFiddle page.

What is http JSFiddle net?

JSFiddle is an online IDE service and online community for testing and showcasing user-created and collaborational HTML, CSS and JavaScript code snippets, known as 'fiddles'. It allows for simulated AJAX calls.


2 Answers

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.

like image 112
Joe Avatar answered Sep 22 '22 02:09

Joe


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);;
    });​ 
});
like image 27
Eat at Joes Avatar answered Sep 23 '22 02:09

Eat at Joes