Stop jQuery function from executing
up vote
0
down vote
favorite
I want a save function to check if a session is set (using another function) and stop the base function from continuing, but the function seems to continue (not executable below):
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else //continue
);
jquery execution
add a comment |
up vote
0
down vote
favorite
I want a save function to check if a session is set (using another function) and stop the base function from continuing, but the function seems to continue (not executable below):
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else //continue
);
jquery execution
1
$.ajax
is asynchronous, that means the following code will continue executing and it's not blocking. Also even if this was intended to be a blocking call it wont work,return
is only for the function it was called in. It doesn't propagate to the outer function that called and causes that one to return it nor should it.
– Spencer Wieczorek
Nov 10 at 8:02
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want a save function to check if a session is set (using another function) and stop the base function from continuing, but the function seems to continue (not executable below):
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else //continue
);
jquery execution
I want a save function to check if a session is set (using another function) and stop the base function from continuing, but the function seems to continue (not executable below):
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else //continue
);
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else //continue
);
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else //continue
);
jquery execution
jquery execution
edited Nov 10 at 8:00
Foo
1
1
asked Nov 10 at 7:47
Kevin Lindmark
2201515
2201515
1
$.ajax
is asynchronous, that means the following code will continue executing and it's not blocking. Also even if this was intended to be a blocking call it wont work,return
is only for the function it was called in. It doesn't propagate to the outer function that called and causes that one to return it nor should it.
– Spencer Wieczorek
Nov 10 at 8:02
add a comment |
1
$.ajax
is asynchronous, that means the following code will continue executing and it's not blocking. Also even if this was intended to be a blocking call it wont work,return
is only for the function it was called in. It doesn't propagate to the outer function that called and causes that one to return it nor should it.
– Spencer Wieczorek
Nov 10 at 8:02
1
1
$.ajax
is asynchronous, that means the following code will continue executing and it's not blocking. Also even if this was intended to be a blocking call it wont work, return
is only for the function it was called in. It doesn't propagate to the outer function that called and causes that one to return it nor should it.– Spencer Wieczorek
Nov 10 at 8:02
$.ajax
is asynchronous, that means the following code will continue executing and it's not blocking. Also even if this was intended to be a blocking call it wont work, return
is only for the function it was called in. It doesn't propagate to the outer function that called and causes that one to return it nor should it.– Spencer Wieczorek
Nov 10 at 8:02
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
let checksession
's AJAX success
callback be the function that performs the "save" operation (or not)
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
console.log( "stop" );
else
console.log( "continue" );
doSave();
);
//3. Perform save operation
function doSave()
//
// proceed with the save operation
//
add a comment |
up vote
0
down vote
Try this:
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
check();
if(check()==true)
continue;
else
stop
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function check()
var result=false;
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else
result=true;
//continue
);
return result;
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
let checksession
's AJAX success
callback be the function that performs the "save" operation (or not)
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
console.log( "stop" );
else
console.log( "continue" );
doSave();
);
//3. Perform save operation
function doSave()
//
// proceed with the save operation
//
add a comment |
up vote
1
down vote
accepted
let checksession
's AJAX success
callback be the function that performs the "save" operation (or not)
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
console.log( "stop" );
else
console.log( "continue" );
doSave();
);
//3. Perform save operation
function doSave()
//
// proceed with the save operation
//
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
let checksession
's AJAX success
callback be the function that performs the "save" operation (or not)
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
console.log( "stop" );
else
console.log( "continue" );
doSave();
);
//3. Perform save operation
function doSave()
//
// proceed with the save operation
//
let checksession
's AJAX success
callback be the function that performs the "save" operation (or not)
//1. Base save function
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
checksession();
);
//2. Session check function
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
console.log( "stop" );
else
console.log( "continue" );
doSave();
);
//3. Perform save operation
function doSave()
//
// proceed with the save operation
//
answered Nov 10 at 7:57
Paolo
9,443244766
9,443244766
add a comment |
add a comment |
up vote
0
down vote
Try this:
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
check();
if(check()==true)
continue;
else
stop
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function check()
var result=false;
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else
result=true;
//continue
);
return result;
add a comment |
up vote
0
down vote
Try this:
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
check();
if(check()==true)
continue;
else
stop
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function check()
var result=false;
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else
result=true;
//continue
);
return result;
add a comment |
up vote
0
down vote
up vote
0
down vote
Try this:
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
check();
if(check()==true)
continue;
else
stop
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function check()
var result=false;
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else
result=true;
//continue
);
return result;
Try this:
$("#save").click(function (e)
e.preventDefault();
//step 0 check if logged in
check();
if(check()==true)
continue;
else
stop
console.log("teststop"); //just for testing
//steps x continue execution of session exists
);
//2. Session check function
function check()
var result=false;
function checksession()
$.ajax(
type: "GET",
url:"xxxx/sessioncheck.php",
dataType: "text",
cache: false,
success: function(data)
if(data == "no")
return;
else
result=true;
//continue
);
return result;
answered Nov 10 at 9:39
shaghayegh sheykholeslami
1847
1847
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237020%2fstop-jquery-function-from-executing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$.ajax
is asynchronous, that means the following code will continue executing and it's not blocking. Also even if this was intended to be a blocking call it wont work,return
is only for the function it was called in. It doesn't propagate to the outer function that called and causes that one to return it nor should it.– Spencer Wieczorek
Nov 10 at 8:02