Ajax doesn't execute success function

My code looks like this. The problem is, PHP side does it job and returns right value. But ajax doesn't execute things inside success: function. What am I missing?

AnswerDiv.on("click", ".NotSelectedAnswer", function() {
    var NotSelectedAnswerBtn = $(".NotSelectedAnswer"),
        SelectedAnswerBtn = $(".SelectedAnswer"),
        AnswerDiv = $("div.Answer"),
        querystring="fromID="+SelectedAnswerBtn.data("id")+"&toID="+$(this).data("id")+"&op=SelectAsAnswer";

    $.ajax({
        url: 'processor.php',
        type: "POST",
        dataType: "json",
        data: querystring,
        success: function(data) {
            if(data.status)
            {
                SelectedAnswerBtn.removeClass("SelectedAnswer").addClass("NotSelectedAnswer").button("enable");
                $(this).removeClass(" NotSelectedAnswer").addClass("SelectedAnswer").button("disable");
                $("div.Answer[data-id=" + SelectedAnswerBtn.data("id") + "]").toggleClass("SelectedDiv");
                $("div.Answer[data-id=" + $(this).data("id") + "]").toggleClass("SelectedDiv");
            }
        }
    });

    return false;
});

Answers


Try to cache $(this) before ajax call

AnswerDiv.on("click", ".NotSelectedAnswer", function() {
    var NotSelectedAnswerBtn = $(".NotSelectedAnswer"),
    SelectedAnswerBtn = $(".SelectedAnswer"),
    AnswerDiv = $("div.Answer"),
    thisElem=$(this),
    querystring="fromID="+SelectedAnswerBtn.data("id")+"&toID="+$(this).data("id")+"&op=SelectAsAnswer";
    $.ajax({
        url: 'processor.php',
        type: "POST",
        dataType: "json",
        data: querystring,
        success: function(data) {
            if(data.status)
            {
                SelectedAnswerBtn.removeClass("SelectedAnswer").addClass("NotSelectedAnswer").button("enable");
                thisElem.removeClass(" NotSelectedAnswer").addClass("SelectedAnswer").button("disable");
                $("div.Answer[data-id=" + SelectedAnswerBtn.data("id") + "]").toggleClass("SelectedDiv");
                $("div.Answer[data-id=" +thisElem.data("id")+ "]").toggleClass("SelectedDiv");
                return false;
            }
        }
    });

});

Need Your Help

Posting data in PHP Curl

php post file-upload curl zoho

I am trying to post the content in a file as a param using PHP CURL.

mongodb update push array

node.js mongodb sails.js

I have the following schema. I am using node.js with mongodb

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.