ajax get data javascript code example
Example 1: jquery ajax get
$.ajax({
url: "www.site.com/page",
success: function(data){
$('#data').text(data);
},
error: function(){
alert("There was an error.");
}
});
Example 2: ajax data post call in javascript
$.ajax({
url: 'ajaxfile.php',
type: 'post',
data: {name:'yogesh',salary: 35000,email: '[email protected]'},
success: function(response){
}
});
Example 3: js ajax receive html
$.ajax({
type: 'POST',
url: "<Your URL>",
contentType: 'application/json; charset=utf-8'
dataType: 'html',
data: { example: 1, id: "0x100"},
success: function (data){
$('#<Your html element id>').html(data);
}
});