JQuery-Django If Statement is Not Working

I'm trying to add a simple popup window to my Django app. How it works is when I press the Yes button, it sends a request to my Django views. However, I want it to automatically close after I press Yes. Unfortunately, the problem with putting it directly in my "click" function is that it closes the window altogether without sending a request to my Django views.

That is why I wanted to add a variable "clicked". After the button is clicked, I want it to change the variable value to "true" so that I can run an if statement ultimately to close the window. For some reason, the popup window automatically closes when I try to open it. My guess is that the if statement is not working properly? Thank you for your help!

$(document).ready(function(){
    var clicked=false;
    var deleteid;
    $('#yes').click(function(){

        deleteid = $(this).attr("data-deleteid");
        $.get ('../../delete_function/', {delete_id:deleteid}, function(data){});
        clicked = true;
    });
    if (clicked = true){
        window.close();
    }
});

Answers


Close the window in the callback function of $.get.

$.get ('../../delete_function/', {delete_id:deleteid}, function(){
    window.close();
});

Your if (clicked == true) is only running when the page is loaded, because it's not inside any event handler. At that point, the button obviously hasn't been clicked yet, so it doesn't do anything.

If you call window.close() directly from the click handler, it will close the window before the AJAX call has a chance to run. When you close a window, all script it was running, including any AJAX operations that were queued, are killed.


Need Your Help

unit tests for boost::optional

c++ unit-testing boost

Where can I find the unit tests for boost::optional?

Input text file of strings and integers

python arrays string integer

I have a data file (ordered_data.txt) composed of 8 columns of integers and the last column is a string. It is 2912 rows long. I am inputting the data like so:

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.