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.
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);;
});
});
来源:https://stackoverflow.com/questions/7374271/how-to-use-ajax-request-in-jsfiddle