Vikash kumar sen
Vikash kumar sen

Reputation: 33

How to read ajax success response

c# code

   string temp3 = dt.ToString();

            cmd.Connection = con;
            con.Open();
            i = cmd.ExecuteNonQuery();
            con.Close();

            if (i == 1)
            {
                msg = "Record Sucessfuly inserted";
            }
            else
            {
                msg = "Error";
            }
           
            //ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + msg + "')", true);
        }
    }
    else
    {
        msg="MCQ";
    }

j-query code

     $.ajax({
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    url: "AddQuestions.aspx/SaveClickFunc",
                    data: "{ 'questionData': '" + JSON.stringify(obj) + "' }", 
                    
                    success: function (response) {
                        console.log(response);
                        
                        
                        if (response == "MCQ") {
                            console.log("MCQ");
                            alert('You can not enter more than' + $("#MCQ").text()+' MCQ Questions');
                            
                        }
                        else if (response == "SUBJ") {
                            console.log("SUBJ");
                            alert('You can not enter any more Subjective Questions');
                        }
                    },

                });

I first send data from aspx page using ajax and after that return a msg after completing c# function I am not getting any alert and if i try alert(response) it returns "[object][object]"

Upvotes: 1

Views: 249

Answers (1)

Vikash kumar sen
Vikash kumar sen

Reputation: 33

the answers is so simple just replace

    (response == "MCQ") 

by

    (response.d == "MCQ")

Upvotes: 1

Related Questions