Found 7800 Articles for Front End Technology

How to use POST method to send data in jQuery Ajax?

Amit D
Updated on 15-Jun-2020 08:52:44
The jQuery.post( url, [data], [callback], [type] ) method loads a page from the server using a POST HTTP request.Here is the description of all the parameters used by this method −url − A string containing the URL to which the request is sentdata − This optional parameter represents key/value pairs or the return value of the .serialize() function that will be sent to the server.callback − This optional parameter represents a function to be executed whenever the data is loaded successfully.type − This optional parameter represents a type of data to be returned to callback function: "xml", "html", "script", "json", "jsonp", or "text".Let’s say ... Read More

What is the difference between jQuery.load() and jQuery.get() methods in jQuery?

Ricky Barnes
Updated on 17-Feb-2020 07:17:43
jQuery load() methodThe load( url, data, callback ) method loads data from the server and places the returned HTML into the matched element.Here is the description of all the parameters used by this method −url − A string containing the URL to which the request is sent.data − This optional parameter represents a map of data that is sent with the request.callback − This optional parameter represents a function that is executed if the request succeedsAssuming we have following HTML content in result.html file:THIS IS RESULT...ExampleThe following is the code snippet showing the usage of this method.            ... Read More

What is the difference between jQuery.load() and jQuery.ajax() methods in jQuery?

Ricky Barnes
Updated on 17-Feb-2020 07:23:14
jQuery ajax() methodThe jQuery.ajax( options ) method loads a remote page using an HTTP request. $.ajax() returns the XMLHttpRequest that it creates. In most cases you won't need that object to manipulate directly, but it is available if you need to abort the request manually.Here is the description of all the parameters used by this method −options − A set of key/value pairs that configure the Ajax request. All options are optional.Assuming we have the following HTML content in result.html file −THIS IS RESULT...ExampleThe following is an example showing the usage of this method. Here, we make use of success handler to ... Read More

What is jQuery.ajaxSetup() method in jQuery?

Amit D
Updated on 15-Jun-2020 08:50:16
The jQuery.ajaxSetup() method sets global settings for future AJAX requests. Here is the description of all the parameters used by this method-Let’s say we have the following HTML content in result.html file,THIS IS RESULT...The following is an example showing the usage of this method. Here we make use of success handler to populate returned HTML:           The jQuery Example                              $(document).ready(function() {                         $("#driver").click(function(event){                // Do global setting.                $.ajaxSetup({                   url: "result.html"                });                                    $.ajax( {                   success:function(data) {                      $('#stage').html(data);                   }                });             });          });                             Click on the button to load result.html file:                        STAGE                                 Live Demo

How to load a page in div using jQuery?

Amit D
Updated on 17-Feb-2020 07:25:03
To load a page in div in jQuery, use the load() method. Firstly, add the web page you want to add.Here’s the code for new.html −     This is demo text. ExampleNow, the code snippet for the file which adds the above page, $(document).ready(function() {        $('#content').load("new.html"); });

What is the difference between jQuery.post() and jQuery.get() methods in jQuery?

Ricky Barnes
Updated on 17-Feb-2020 07:13:59
jQuery post() methodThe jQuery.post( url, [data], [callback], [type] ) method loads a page from the server using a POST HTTP request.Assuming we have following PHP content in result.php file, ExampleThe following is the code snippet showing the usage of this method −                                 $(document).ready(function() {                         $("#driver").click(function(event){                                $.post(                   "result.php", ... Read More

What does jQuery.serialize() method do in jQuery?

Ricky Barnes
Updated on 17-Feb-2020 07:07:40
The serialize() method serializes a set of input elements into a string of data. Let’s say we have the following PHP content in serialize.php file −ExampleThe following is the code snippet showing the usage of this method −                                 $(document).ready(function() {                         $("#driver").click(function(event){                                $.post(                   "/jquery/serialize.php",                   $("#testform").serialize(),                                           function(data) {                      $('#stage1').html(data);                   }                    );                                    var str = $("#testform").serialize();                $("#stage2").text(str);             });                          });                             Click on the button to load result.html file:                        STAGE - 1                                    STAGE - 2                                                                      Name:                                                                        Age:                                                                                        Sex:                                                       Male                   Female                                                                                                                                                                                          

How to put a complete HTML page in a div using jQuery?

Ricky Barnes
Updated on 17-Feb-2020 07:06:12
To put complete HTML page in a div using jQuery, use the load() method. Firstly, add the web page you want to add.Here’s the code for new.html −     Heading 1 Demo text ExampleNow, the code for the HTML file which adds the above page, $(document).ready(function(){        $('#myid').load("new.html"); });

How to use jQuery.getJSON to load JSON file in jQuery?

Ricky Barnes
Updated on 17-Feb-2020 07:04:28
The jQuery.getJSON( url, [data], [callback] ) method loads JSON data from the server using a GET HTTP request.Assuming we have the following JSON content in result.json file −{ "name": "Amy", "age" : "24", "sex": "female" }ExampleThe following is the code snippet showing the usage of this method −                                 $(document).ready(function() {                         $("#driver").click(function(event){                $.getJSON('result.json', function(jd) {                   $('#stage').html(' Name: ' + jd.name + '');                   $('#stage').append('Age : ' + jd.age+ '');                   $('#stage').append(' Sex: ' + jd.sex+ '');                });             });                          });                             Click on the button to load result.html file:                        STAGE                                

How to use jQuery.getScript() method to load external js files?

Ricky Barnes
Updated on 17-Feb-2020 07:03:25
The jQuery.getScript( url, [callback] ) method loads and executes a JavaScript file using an HTTP GET request.Here is the description of all the parameters used by this method −url − A string containing the URL to which the request is sentcallback − This optional parameter represents a function to be executed whenever the data is loaded successfully.Assuming we have following JavaScript content in result.js file −function CheckJS(){    alert("This is JavaScript"); }ExampleThe following is the code snippet showing the usage of this method −                              $(document).ready(function() {   ... Read More
Advertisements