Handle jQuery AJAX Error

David Meador
Updated on 15-Jun-2020 09:04:44

2K+ Views

To handle jQuery AJAX error. The ajaxError( callback ) method attaches a function to be executed whenever an AJAX request fails. This is an Ajax Event.Here is the description of all the parameters used by this method −callback − The function to execute. The XMLHttpRequest and settings used for that request are passed as arguments to this function. A third argument, an exception object, is passed if an exception occured while processing the request.The following is an example showing the usage of this method:Live Demo           Handling errors in jQuery           ... Read More

Creating a Queue in JavaScript

Samual Sam
Updated on 15-Jun-2020 09:02:25

732 Views

Though Arrays in JavaScript provide all the functionality of a Queue, let us implement our own Queue class. Our class will have the following functions − enqueue(element): Function to add an element in the queue. dequeue(): Function that removes an element from the queue. peek(): Returns the element from the front of the queue. isFull(): Checks if we reached the element limit on the queue. isEmpty(): checks if the queue is empty. clear(): Remove all elements. display(): display all contents of the arrayLet's start by defining a simple class with a constructor that takes the max size of the queue and a helper function that'll help us ... Read More

Remove Elements from a Queue Using JavaScript

Samual Sam
Updated on 15-Jun-2020 08:59:21

922 Views

Dequeuing elements from a Queue means removing them from the front/head of the queue. We are taking the start of the container array to be the head of the queue as we'll perform all operations with respect to it.Hence, we can implement the pop function as follows − Exampledequeue() {    // Check if empty    if (this.isEmpty()) {       console.log("Queue Underflow!");       return;    }    return this.container.shift(); }You can check if this function is working fine using − Examplelet q = new Queue(2); q.dequeue(); q.enqueue(3); q.enqueue(4); console.log(q.dequeue()); q.display();OutputThis will give the output −Queue Underflow! 3 [ ... Read More

Peeking Elements from a Queue in JavaScript

karthikeya Boyini
Updated on 15-Jun-2020 08:57:26

647 Views

Peeking a Queue means getting the value at the head of the Queue. So we can implement the peek function as follows − EXamplepeek() {    if (isEmpty()) {       console.log("Queue Underflow!");       return;    }    return this.container[0]; }You can check if this function is working fine using − Examplelet q = new Queue(2); q.enqueue(3); q.enqueue(4); console.log(q.peek()); q.display();OutputThis will give the output −3 [ 3, 4 ]As you can see here, peek() differs from dequeue in that it just returns the front value without removing it.

Clearing Elements of the Queue in JavaScript

Samual Sam
Updated on 15-Jun-2020 08:56:02

402 Views

We can clear the contents just by reassigning the container element to an empty array. For example, clear() {    this.container = []; }ExampleYou can check if this function is working fine using:let q = new Queue(2); q.enqueue(3); q.enqueue(4); q.display(); q.clear(); q.display();OutputThis will give the output:[ 3, 4 ] [ ]

The Queue Class in JavaScript

karthikeya Boyini
Updated on 15-Jun-2020 08:55:35

286 Views

Here is the complete implementation of the Queue class −Exampleclass Queue {    constructor(maxSize) {       // Set default max size if not provided       if (isNaN(maxSize)) {          maxSize = 10;       }       this.maxSize = maxSize;       // Init an array that'll contain the queue values.       this.container = [];     }    // Helper function to display all values while developing    display() {       console.log(this.container);    }    // Checks if queue is empty    isEmpty() {   ... Read More

Creating a Priority Queue using JavaScript

karthikeya Boyini
Updated on 15-Jun-2020 08:54:25

525 Views

Our class will have the following functions −enqueue(element): Function to add an element in the queue.dequeue(): Function that removes an element from the queue.peek(): Returns the element from the front of the queue.isFull(): Checks if we reached the element limit on the queue.isEmpty(): checks if the queue is empty.clear(): Remove all elements.display(): display all contents of the arrayLet's start by defining a simple class with a constructor that takes the max size of the queue and a helper function that'll help us when we implement the other functions for this class. We'll also have to define another structure as part ... Read More

Add Elements to a PriorityQueue Using JavaScript

Samual Sam
Updated on 15-Jun-2020 08:53:23

227 Views

Enqueuing elements to a PriorityQueue means adding them in the array in order of the priority of the element. We'll consider higher numbers to be higher priorities. We'll loop through the container till we find a lower priority and then add the element there. If not, then we'll push it at the end of the container.Note that we're creating the element object with the data and priority. Hence we can implement the enqueue function as follows −  Exampleenqueue(data, priority) {    // Check if Queue is full    if (this.isFull()) {       console.log("Queue Overflow!");       return; ... Read More

Use POST Method to Send Data in jQuery Ajax

Amit D
Updated on 15-Jun-2020 08:52:44

4K+ Views

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

Delete Bookmarks in Your Browser: Firefox & Chrome

Rahul Sharma
Updated on 15-Jun-2020 08:51:40

272 Views

Bookmarks in a web browser are saved so that it can be referred. It is also known as favorite web pages. To Bookmark a web page, visit the page and press Ctrl+D. This will give you an option to save the web page.In this way, all the bookmarks get saved like this on pressing Ctrl+D. The star sign as you can see below also allows you to add a bookmark −Bookmark on FirefoxBookmark on ChromeLet’s learn how to delete a bookmark in a web browser. To delete a bookmark, which you bookmarked before in Firefox or Chrome, you need to ... Read More

Advertisements