Do AJAX requests hinder performance and how long do they typically last?

Even though I have experience in web development, I still find myself feeling a bit uneasy asking these basic questions. However, I believe it's always good to verify my assumptions...

In my application, I am working on recording unique image views. When a user (not a bot) visits an image page, there is an Ajax call made to a back-end process that gathers session information, checks for duplicates, and saves the visit. All my JavaScript references, along with this call, are placed at the end of the HTML, right before the </body> tag:

$.get(basepath + "image/1329/record/human", function(data){
console.log("Data Loaded: " + data);
});

By default, the $.get call is asynchronous. But I want to confirm the following assumptions:

  • Will this method ensure that the call to the view recording script does not block the rest of the UI?
  • Will the back-end script complete its task once called, even if the user navigates to another page?

Answer №1

As per information from the jQuery .get reference page...

The method [$.get()] is a condensed Ajax function that performs the same task as:

$.ajax({ url: url,   data: data,  
         success: success,   dataType: dataType
});

It's worth noting that $.ajax operates asynchronously (i.e. non-blocking) by default, in line with the "A" in Ajax.

In addition, server-side code initiated upon receiving a request continues to run independently of whether the client remains on the page or not, unless specific measures are taken to halt the process - which I assume have not been implemented in this case.

Have a blessed day!

Answer №2

When you use the jQuery.get request, it operates asynchronously, allowing the DOM and other JavaScript to continue running without being blocked. The get function is basically a shortcut method that leverages jQuery.ajax.

As for the second question, there isn't a straightforward answer as it could vary depending on how the backend code is structured and whether it recognizes that the session or request has ended.

For more information on the API:

Answer №3

you are right on both points

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The value of `$(this).data('dynamic_id')` is only defined within the `alert` function

Can someone please provide guidance on how to pass dynamically generated IDs from a Rails app to jQuery using the data-attribute? I have encountered an issue where the value returns as undefined unless it is sent to an alert box. I am currently using this ...

Retrieve the HTML content of all children except for a specific child element in jQuery

Is there a way to utilize jQuery/Javascript for selecting the HTML content of the two <p> elements in the initial <div class="description? I'm open to using Regex as well. This specific jQuery selection is being executed within Node.js on a c ...

Ways to prevent recurring variables in Twitter bootstrap dialogues

I need assistance with deleting multiple links using ajax: <a id="id-1">link1</a> <a id="id-2">link2</a> <a id="id-3">link2</a> <a id="id-4">link2</a> ... This is the simplified version of my code: $(docum ...

Automatically updating d3.js data in real-time using jQuery's setInterval function with support for JSON, XML, text, and other data

Is there anyone who can provide guidance on how to use jQuery's get method (for json, txt, xml, or any other format) in conjunction with setInterval from d3.js? I'm looking to update my d3 bar chart every N seconds. Alternatively, is there an exi ...

What is the process for incorporating an additional input in HTML as you write?

I am looking to create a form with 4 input boxes similar to the layout below: <input type="text" name="txtName" value="Text 1" id="txt" /> <input type="text" name="txtName2" value="Text 2" id="txt" /> <input type="text" name="txtName3" valu ...

The count in the document is not increasing

I am facing an issue where a file on the server contains a counter, and when a link is clicked, an ajax request is sent to a PHP file to increment the counter in the file. However, the file is being created without the counter being incremented. Interesti ...

Incorporating Ruby on Rails: Sending a fresh POST request to API and instantly

I'm a beginner in the field of ruby on rails. Our website allows users to search and receive a list of results. Now, I want to incorporate sorting functionality for the results (by price, rating, etc). The API handles the sorting process, so all I ne ...

Is there a way to bring together scrolling effects and mouse movement for a dynamic user

If you want to see a scrolling effect, check out this link here. For another animation on mouse move, click on this link(here). Combining both the scrolling effect and the image movement might seem challenging due to different styles used in each templat ...

PHP and AJAX can sometimes cause variable values to become lost

I've been encountering an issue while attempting to validate an email using ajax. For some reason, the mail variable seems to disappear during the process. Despite thoroughly checking for typos multiple times, I can't seem to locate any errors. T ...

Ways to extract useful information from a JSON response

Upon receiving a response from the server with details about various flowers and their quantities, I aim to display this information in a table. However, I am facing difficulty retrieving the values for the "Quantity" column. The code snippet below showcas ...

When working with AngularJS, you can enhance your application by implementing a global AJAX error handler if one has

Is there a way to set a global AJAX handler that will only be called if an error handler is not already defined for a specific AJAX call? Some of my AJAX calls need to execute certain logic if an error occurs (such as re-enabling a button), while others s ...

Guidelines for submitting and displaying content on a single page with jQuery and MySQL

Objective: To develop a Q&A Script using PHP, JavaScript, and jQuery that allows users to post questions and provide answers. Upon submitting a new answer, it should be stored in the database and automatically displayed in the answers section. Challenge: ...

Using PHP to extract information from a JSON file

After researching various articles and tutorials, I've managed to piece together the code below. However, as a beginner in PHP, JSON, and Javascript, I am seeking guidance. The task at hand is to update a div with the ID "playerName" every 10 seconds ...

The persistent problem with constantly polling the $.ajax request

One issue I'm facing involves a continuous polling $.ajax request. The challenge lies in initiating it immediately first, and then running it at intervals set in the setTimeout call. Take a look at the example code here. myObj = {}; var output = ...

Determine the minimum and maximum width of jQuery UI resizable during the "resizestart" event

As a newcomer to Javascript, I am facing challenges navigating my way around. Currently, I am attempting to create a jQuery plugin that will facilitate resizing elements using the jQuery UI resizable plugin. My goal is to implement logic that dynamically ...

Disable hyperlink after it has been selected using Ajax

<script type="text/javascript"> var url = document.URL; var strg = url.toString(); function StartAjax(ResultsId){ $.ajax({ type: "GET", url: "mark.php", cache: false, data: (strg), success: function(html){ ...

When utilizing jQuery.ajax() for JSONP, if a parse error occurs, the error callback will be triggered instead of the success callback despite receiving a status

Initially, I have reviewed similar posts on the website but none of them have resolved my issue. My requirement is to fetch a JSON file from a web server. The JSON file has been validated by JSONLint, ensuring the syntax is correct. The data in JSON forma ...

Retrieving the current value of the selected option using JQuery

I am working on a feature where I have different quantities in selects after each button click. <button type="button" class="btn btn-sm btn-primary" id="addtocart2" >Button1</button> <select id="quantity1" class="ml- ...

Passing a variable through jQuery onClick event to a URL via GET request and subsequently loading the content of

After successfully passing variables through AJAX calls via onClick to a PHP file and loading the results on the initial page, I now face the challenge of passing a variable analogously via onClick to a PHP file but this time I need to either open a new wi ...

The issue of not displaying results in a DIV when using CakePHP 2 and jQuery

I'm having trouble creating an auto-refreshing DIV with updated data. Despite everything appearing to be correct, it's not displaying any results on the webpage. Any assistance would be greatly appreciated :) Controller: public function homeNe ...