ihue ihue - 1 year ago 65
Javascript Question

What are the alternative ways of making an Ajax call?

I'm wondering what is the best way to make an AJAX call.

This is what I have right now, and it works just fine.


url: "/rest/computer",
type: "GET",
dataType: "json",

data: {
assessmentId: "123",
classroomId: "234"

success: function(objects) {

// .... code ....


I'm currently seeking another ways of making an Ajax call.
If there is, should I use my approach ?

Should I move an Ajax call into it own function and call it back ?

Any suggestions on this will be much appreciated.

Answer Source

Yes there are some other ways to call ajax


var get_data = function(){
    var result = false;
        result = awesome_data;

    return result;


$.getJSON( '/rest/computer', { assessmentId:"123", classroomId:"234"})
  .done( function(resp){
    // handle response here

If you're not using jQuery in your code, this answer is for you

Your code should be something along the lines of this:

function foo() {
    var httpRequest = new XMLHttpRequest();
    httpRequest.open('GET', "/rest/computer");
    return httpRequest.responseText;

var result = foo(); // always ends up being 'undefined'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download