| Start | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Handling HTTP Response Codes with $.ajax() In addition to As official jQuery documentation states: If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error (including 3xx redirect), they take the same parameters as the `error` callback. |
||||||||||||||||||||||
| Using Ajax to Submit a Form Sometimes you may have a form and want to submit it using ajax. Suppose you have this simple form - The following jQuery code can be used (within a Explanation
|
||||||||||||||||||||||
| All in one examples Ajax Get: Solution 1: Solution 2: Ajax Load: Another ajax get method created for simplcity .load can also be called with additional data. The data part can be provided as string or object. If .load is called with a callback method, the request to the server will be a post Ajax Post: Solution 1: Solution 2: Ajax Post JSON: Ajax Get JSON: Solution 1: Solution 2: |
||||||||||||||||||||||
Ajax File Uploads 1. A Simple Complete ExampleWe could use this sample code to upload the files selected by the user every time a new file selection is made. Now let's break this down and inspect it part by part. 2. Working With File InputsThis MDN Document ( Using files from web applications ) (opens new window) is a good read about various methods on how to handle file inputs. Some of these methods will also be used in this example. Before we get to uploading files, we first need to give the user a way to select the files they want to upload. For this purpose we will use a We will be using input's Inside the handler function, we access the files through the files property of our input. This gives us a FileList (opens new window), which is an array like object. 3. Creating and Filling the FormDataIn order to upload files with Ajax we are going to use FormData (opens new window). FileList (opens new window) we have obtained in the previous step is an array like object and can be iterated using various methods including for loop (opens new window), for...of loop (opens new window) and jQuery.each (opens new window). We will be sticking with the jQuery in this example. We will be using the append method (opens new window) of FormData to add the files into our formdata object. We can also add other data we want to send the same way. Let's say we want to send some personal information we have received from the user along with the files. We could add this this information into our formdata object. 4. Sending the Files With AjaxWe set |
||||||||||||||||||||||
Ajax Abort a Call or Request //kill the request |
||||||||||||||||||||||
| Sending JSON data jQuery makes handling jSON responses painless, but a bit more work is required when a given request wishes you to send data in JSON format: Observe that we're specifying the correct The call to Syntax
Parameters
RemarksAJAX stands for Asynchronous JavaScript and XML. AJAX allows a webpage to perform an asynchronous HTTP (AJAX) request to the server and receive a response, without needing to reload the entire page. |
Read Article
https://develop.horje.com/learn/1434/reference