make ajax calls with jQuery

// GET Request
    $.ajax({
        url: "example.php?firstParam=Hello&secondParam=World", //you can also pass get parameters
        dataType: 'json',	//dataType you expect in the response from the server
        timeout: 2000
    }).done(function (data, textStatus, jqXHR) {
        //your code here
    }).fail(function (jqXHR, textStatus, errorThrown) {
        console.log("jqXHR:" + jqXHR);
        console.log("TestStatus: " + textStatus);
        console.log("ErrorThrown: " + errorThrown);
    });

//POST Request
    var formData = {name: "John", surname: "Doe", age: "31"}; //Array 
    $.ajax({
        url: "example.php",
        type: "POST", // data type (can be get, post, put, delete)
        data: formData, // data in json format
       	timeout: 2000,	//Is useful ONLY if async=true. If async=false it is useless
        async: false, // enable or disable async (optional, but suggested as false if you need to populate data afterwards)
        success: function (data, textStatus, jqXHR) {
            //your code here
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.log("jqXHR:" + jqXHR);
            console.log("TestStatus: " + textStatus);
            console.log("ErrorThrown: " + errorThrown);
        }
    });


//Alternatively, the old aproach is
    $.ajax({
        url: "api.php?action=getCategories",
        dataType: 'json',
        timeout: 2000,
        success: function (result, textStatus, jqXHR) {   //jqXHR = jQuery XMLHttpRequest
            /*You could put your code here but this way of doing it is obsolete. Better to use .done()*/
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.log("jqXHR:" + jqXHR);
            console.log("TestStatus: " + textStatus);
            console.log("ErrorThrown: " + errorThrown);
        }
    });

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
making an ajax request call ajax inside ajax ajax jquery function example simple jQuery AJAX statement how to create ajax function in jquery jquery with ajax making ajax request ajax calls in jquery what script for ajax call put ajax call jquery ajax use in jquery how to handle ajax call response in jquery jquery ajax done example how to write ajax call in jquery call ajax using jquery jquery.ajax call how to use jquery html function in ajax jquery use ajax in ajax ajax example in jquery how to make an ajax call create an ajax request jquery ajax in function using jquery and ajax ajax method jquery explained how to use ajax response in jquery what function do in ajax jquerry Call java method from jquery using ajax example make a request with ajax ajax inside js function jquery .ajax example How to write an ajax call in jquery Using jquery for AJAX make ajax call jquery jquery and ajax request jquery ajax method jquery function using ajax jquery ajax call example jquery call ajax ajax call using jquery different ajax call jquery sample ajax call jquery ajax call jquery syntax make ajax call ajax in jquery example ajax jquery call jquery ajax example steps to write ajax in jquery how to write ajax in jquery steps on how to use ajax in jquery ajax call in detailed in jquery how to make ajax request in jquery use ajax with jquery create ajax function to call a funcion ajax calling in jquery how to make an ajax call in jquery ajax inside ajax jqueyr ajax in a function jquery.ajaxy.js html page make ajax request jquery ajax methods jquery jquery ajax sample code jquery apply ajax calls .ajax jquery example simple ajax call in jquery ajax call examples ajax using jquery $(ajax).function({ jquery ajax examples call ajax function using js ajax jquery simple call example ajax call tutorial how to specify the method in ajax html jquery ajax call jquery ajax response function on ajax call jquery request ajax in jquery how to make ajax request Make an AJAX request add ajax in function and call ajax request jquery example jquery ajax methods WITH ?page how can i make ajax request ajax functions What are the various ajax functions available in jQuery What are the various ajax functions available in jQuery ? how to call function in ajax jquery how to make an ajax request making ajax call in javascript how to ajax call in jquery jquery when ajax as function call how to put ajax call in function then in ajax call jquery call a function using ajax ajax jquery function call ajax in function ajax call in jquery tutorial creating ajax request simple ajax request jquery html make ajax call call javascript function ajax html ajax example jquery ajax function in jquery using jquery ajax inside js function need to ajax call example call ajax ajax sample request jquery jquery ajax done function jquery ajax sample $.ajax( ) example ajax sample code jquery call jquery on ajax response jquery ajax on response how to use ajax with jquery make an AJAX call using jQuery jquery methods ajax jquery ajax request example what are different ways to make ajax calls jquery simple ajax call ajax call function in jquery call jquery ajax ajax example jquery $.ajax example jquery how to run ajax code in function from jquery make ajax request jquery example ajax jquer ajax call sample ajax call in jquery jquery ajax request method AJAX CALL WITH JQUERY ajax method in jquery js ajax function call how to use ajax call inside the ajax request ajax request example jquery execute ajax what does an ajax request to jquery what does an ajax request do jquery ajax function jquery how to use ajax in jquery how to call function in ajax in ja ajax jquery example how to make ajax call ajax call in jquery jquery ajax functions ajax call jquery how to use jquery with ajax jquery ajax call ajax with jquery example jquery ajax jquery ajax example ajax calls jQuery jquery ajax then example ajax calls with jQuery make ajax calls with jQuery
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source