0

i'm newbie to javascript and i have create a function by myself but it's not working

function oi_delete(ns_oi){
alert("Are You Sure About DELETE image # " + ns_oi + " ?");
$.post('insert.php', {ns_oi:ns_oi});
location.reload();}

alert and location is working but seconde line: $.post('insert.php', {ns_oi:ns_oi}); is not working or maybe working wrong!

i have create this function to send a value "ns_oi" to insert.php and in insert.php i have get that value and do something

can anyone help me and say what is the problem?

3
  • 2
    You're using AJAX, why you want to reload whole page? Commented Oct 26, 2013 at 9:22
  • 2
    You're doing location.reload which refreshes the page instantly. The $.post request is asynchronous, it doesn't get the chance to fire before you reload. You can do $.post('insert.php', {ns_oi:ns_oi}).done(function(){ location.reload;}) but you should probably rethink your logic. Why is that location.reload there? Commented Oct 26, 2013 at 9:22
  • 1
    Note that alert() won't allow the user to click No. Use confirm() instead. Commented Oct 26, 2013 at 9:34

1 Answer 1

1

Why don't you send it properly with a jQuery.post() function properly like:

function oi_delete(ns_oi){
    alert("Are You Sure About DELETE image # " + ns_oi + " ?");

    $.post('insert.php', {ns_oi:ns_oi}, function(data) {
        location.reload();
    });

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.