top button
Flag Notify
Site Registration

How to make an ajax call using Java Script and Jquery?

0 votes
524 views

Please give the example for both.

posted Jul 7, 2014 by Pankaj Deshmukh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

With using Javascript

function callAjax(url, callback){
var xmlhttp;
// compatible with IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
        callback(xmlhttp.responseText);
    }
}
xmlhttp.open("GET", url, true);
xmlhttp.send();

}

With using Jquery

$.ajax({
    url: "test.html",
    context: document.body,
    success: function(){
      $(this).addClass("done");
    }
});
answer Aug 13, 2014 by Ujjwal Mehra
Similar Questions
+3 votes

The browser i am using is google chrome. I also tested it in internet explorer and firefox too. But result is same. The post method is working fine for the same rest endpoint, but when i am trying to execute delete method on the same endpoint, it's throwing error with http status code 209 with the reason "failed to form full key for endpoint".

This is how the i am sending the delete request.

$.ajax({
             url: url,
             type: "DELETE",
             dataType:"json",
             data: JSON.stringify(data),
             crossDomain: true,
             contentType:"application/json",
             success:function(result){console.log("Success " + console.log(JSON.stringify(result)))},
             error:function(error){
                        alert("Error Deleting Service.See the console log.");
                        console.log(JSON.stringify(error));
                        },
             }).then(function(response){
                   console.log(JSON.stringify(response));
             });

The POST method:

 $.ajax({
                 url: url,
                 type: "POST",
                 dataType:"json",
                 data: JSON.stringify(data),
                 crossDomain: true,
                 contentType:"application/json; charset=utf-8",
                 success:function(){console.log("Success")},
                 error:function(error){console.log(JSON.stringify(error))},
                 }).then(function(response){
                      console.log(JSON.stringify(response));
                 });

Need help. I have already spent the day on this but not able to find the solution for this. I also tried to append the data params with the url but that too didn't worked.

...