---
title: "How to prevent anchor tag request on ajax response?"  
description: "How to prevent anchor tag request on ajax response?"  
author: "Anonymous User"  
published: 2018-04-03  
updated: 2018-04-04  
canonical: https://www.mindstick.com/forum/34454/how-to-prevent-anchor-tag-request-on-ajax-response  
category: "c#"  
tags: ["mvc"]  
reading_time: 2 minutes  

---

# How to prevent anchor tag request on ajax response?

Hi,

I want to stop [anchor tag](https://www.mindstick.com/forum/156201/what-is-the-use-of-anchor-tag-in-seo) [request](https://www.mindstick.com/blog/255/post-get-and-request-function-in-php) on [ajax](https://www.mindstick.com/articles/1541/check-availability-of-user-name-or-email-using-asp-dot-net-ajax-and-jquery) [response](https://www.mindstick.com/forum/12719/how-to-make-response-write-display-special-character-like-lt-gt).

Here is my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
<a class="anchorTag" href="@Url.Action("ActionName", "ControllerName")" >Click Here...</a>
```

```
<script>$(function () {    $('.anchorTag').click(function (e) {     var data = {            postID: 001        };        $.ajax({            type: "POST",            url: "../../ControllerName/ActionName",            data: JSON.stringify(data),            dataType: "json",            contentType: 'application/json; charset=utf-8',            success: function (response) {                if (response.success == true) {                    
                }                else {                  
                }            }        });    });});</script>
```

Please give me some solution to achieve this task.

## Replies

### Reply by Hemant Patel

Hi Franco,

I analyzed your code. You can achieve your task by using **object.preventDefault().**

But used this method carefully.

Your modified code is as follows:

```
<script>
$(function () {

    $('.anchorTag').click(function (e) {
        e.preventDefault();
        var me = this;



        var data = {
            postID: 001
        };

        $.ajax({
            type: "POST",
            url: "../../ControllerName/ActionName",
            data: JSON.stringify(data),
            dataType: "json",
            contentType: 'application/json; charset=utf-8',
            success: function (response) {
                if (response.success == true) {
                    window.location = $(me).attr("href");
                }
                else {

                }
            }
        });

    });
});
</script>
```

I hope it's informative!!!


---

Original Source: https://www.mindstick.com/forum/34454/how-to-prevent-anchor-tag-request-on-ajax-response

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
