$.ajax({
url: "https://app.asana.com/-/api/0.1/workspaces/",
type: 'GET',
dataType: 'json', // added data type
success: function(res) {
console.log(res);
alert(res);
}
});
$.ajax({
url: "www.site.com/page",
success: function(data){
$('#data').text(data);
},
error: function(){
alert("There was an error.");
}
});
//your jquery code will be like this:
$.ajax({
type: 'POST',
url: $url,
data: new FormData(this),
dataType: 'json',
contentType: false,
processData:false,//this is a must
success: function(response){
$('your_selector').html(response);
}
});
//php code will be like this
echo '<div>some html code</div>';
die();
$(document).ready(function(){
var a ="demo_test.asp";
$("button").click(function(){
$.get("demo_test.asp", function(a){
alert(a);
});
});
});
$.get("demo_test.asp", function(data){ //change demo_test.asp to your server route
alert("Data: " + data);
});
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("demo").innerHTML = this.responseText;
}
xhttp.open("GET", URL);
xhttp.send();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Ajax GET Demo</title>
<script>
function displayFullName() {
// Creating the XMLHttpRequest object
var request = new XMLHttpRequest();
// Instantiating the request object
request.open("GET", "/examples/php/greet.php?fname=John&lname=Clark");
// Defining event listener for readystatechange event
request.onreadystatechange = function() {
// Check if the request is compete and was successful
if(this.readyState === 4 && this.status === 200) {
// Inserting the response from server into an HTML element
document.getElementById("result").innerHTML = this.responseText;
}
};
// Sending the request to the server
request.send();
}
</script>
</head>
<body>
<div id="result">
<p>Content of the result DIV box will be replaced by the server response</p>
</div>
<button type="button" onclick="displayFullName()">Display Full Name</button>
</body>
</html>