Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is the difference between jQuery.get() and jQuery.ajax()?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.91k
    Comment on it

    jQuery.get()

    
    jQuery.get('testing.txt',function(data){
        console.log(data)
    },'text');

    In this blog first we are using the jQuery.get() method. You pass function in arguments instead of passing in an object when you are using jQuery.get(). You have to need the first two arguments that are a success callback and the URL of the file you want to retrieve (i.e. ‘testing.txt’).  In the above example we are also passing another argument i.e text which basically doing is telling jQuery that we wanted to treat the return message as text. 

    The jQuery.get() method is used when you would like to make a quick Ajax call and you are very sure that the type is GET.

    Syntax of jQuery.get() is defined below:

    $.get( url, [data], [callback], [type] )

    Description of  the above parameters used −

    •  url − It is a string that contains the URL in this the request is sent.
    •  data − It is optional parameter. The key-value pairs that will be sent to the server is represented by data.
    • callback − It is optional parameter. Whenever the data is loaded successfully this function has to be executed.
    • type − It is optional parameter. It represents type of data to be returned to callback function. It can be xml, html, script, json, or text.

    jQuery.ajax()

    url: 'testing.txt',
    dataType: 'text',
    type: GET,
      success: function(data) {
        console.log(data);              
      }
    });

    In the above example we are using the jQuery.ajax() method. Here what we are doing is passing an object into the jQuery.ajax() method. jQuery provides the Ajax request method. It considers the creation of highly-customized Ajax requests, with choices for to what extent to sit  for a reaction, how to handle a failure, whether the request that you made is blocking (synchronous) or non-blocking (asynchronous), what configuration to ask for the reaction, and numerous more alternatives.

    Detail of the properties used in jQuery.ajax() are defined below:

    • url:Through ajax call you are gabbing the URL of the file.
    • dataType: How the return data will be treated will be depend on the this datatype.
    • type:  This is the type of the request it can be POST or GET.In jQuery default Post type will be GET.
    • success: After a successful http request then a callback function is fired.

     

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: