How to Stop HTTP Request GET Process using JQuery

Posted on

As written in the title of the article, the main focus on the subject of this article is about how to stop the HTTP Request GET process by using JQuery. Normally, a certain link in the form of tag represented by <a></a> in the web file defined will redirect the page for further processing to the main address of the web server visited. When the link is clicked, at that instance the request in its normal form which is the HTTP Request GET will be sent to the web server device targeted so that it can be further processed.

But certainly in the context of this article, there is a necessity to stop that process using JQuery with several considerations. One of those considerations are the necessity for retrieving or taking the value of the status from several or all elements exist in that web page.

As it can be referred from inside of the web page itself, it might contain many elements which in this context it is referring to the HTML element. HTML element like input text, textarea, select option or any other located inside a page were made in order to be filled by the user.  In the end, after the related user is using it naturally, off course it is going to be filled which is certainly containing information used for further processes.

One clear way for retrieving the value is by utilizing onClick event or using a click event in a link so that JQuery can act to stop the process of sending directly HTTP Request GET. Below is an example given in a link contained in a web page  :

<a id="my_link" href="process.php"></a>

Furthermore, for a script or a snippet code used in order to detect link and also preventing HTTP Request GET process to be executed further, below is the snippet code mentioned  :

$("#my_link").click(function(e){
    e.preventDefault(); 
    e.stopPropagation();
});

Beside the above snippet code or script, after gooling up further, there is also another script which is shorter and it can act with the same function with the above script or snippet code presented. The script is shown below  :

$("#my_link").click(function(e){
    return false;
});

So, in other words, both of the scripts can be used by selecting either one of them to be defined in the page in order to stop the HTTP Request GET process.

Leave a Reply