---
title: "Change css in jquery ajax with asp.net"  
description: "Change css in jquery ajax with asp.net"  
author: "Anonymous User"  
published: 2014-09-02  
updated: 2014-09-03  
canonical: https://www.mindstick.com/forum/2237/change-css-in-jquery-ajax-with-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Change css in jquery ajax with asp.net

I wolud like to get [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results): 2222 .but i can not get the results now.Output '3333' always. can [anyone help me](https://www.mindstick.com/forum/331/can-anyone-help-me-out-how-to-use-session-concept) out ?thank you very much!

```
<head runat="server"><title></title><script src="/Scripts/jquery-1.4.1.js"
type="text/javascript"></script><script language="javascript"
type="text/javascript">    $(function () {       
$("#Button1").click(function () {           
checkCard('333');            var arrlist = $("span[class='error']");            if(arrlist.length > 0) {               
alert('2222')            }            else {               
alert('3333');            }        });    })    function checkCard(card_no) {        $.ajax({            type:"GET",            url:"CheckCard.ashx?card_no=" + card_no,            success:
function (data) {                if(data == "true") {                   
$("#sw").addClass("error");                }                else {                   
$("#sw").removeClass("error");                }            }        });    } </script></head><body> <form
id="form1" runat="server"> <div>    <span id="sw"></span></div></form>    <input id="Button1" type="button" value="button" /></body>
```

## CheckCard.ashx:

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data.SqlClient;namespace SwipeCard{/// <summary>/// Summary description for CheckCard/// </summary>public class CheckCard : IHttpHandler{    public void ProcessRequest(HttpContext context)    {       
context.Response.ContentType = "text/html";       
context.Response.Write("true");       
context.Response.End();    }    public bool IsReusable    {        get        {            return false;        }    }}}
```

I wolud like to get results: 2222 .but i can not get the results now.Output '3333' always. can anyone help me out ?

thank you

## Replies

### Reply by Sumit Kesarwani

Hi Goti,

$.ajax is asynchronous. Your style check immediately follows the call, and thus there is no guarantee that the operation has completed. Put the check in the success callback.

```
function checkCard(card_no) {    $.ajax({        type: "GET",        url: "CheckCard.ashx?card_no=" + card_no,        success: function (data) {            if (data == "true") {                alert("Condition 1 exists");                $("#sw").addClass("error");            }            else {                alert("Condition 2 exists");                $("#sw").removeClass("error");            }        }    });}
```


---

Original Source: https://www.mindstick.com/forum/2237/change-css-in-jquery-ajax-with-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
