Use variable outside the success function from an ajax/jquery call

后端 未结 5 822
北海茫月
北海茫月 2020-11-27 22:04

I have the following code

var test;
     $.ajax({
        type: \"GET\",
        url: \"../views/person/controller.php?actor=person&action=checkAge\",
           


        
5条回答
  •  感动是毒
    2020-11-27 22:43

    What happens when you remove "var" before the term "test" when you declare it?

    I'm not sure how the call back function is treated with jQuery , as it is wrapped within a few other extended methods.. But the reason i say leave var out in the declaration of the test variable is that var assigns test to be relative to the scope. If your callback is being treated in a certain way, you may lose the scope where test is defined. You may want to drop the var assignment and leave it as a global variable. Perhaps this will make it visible?

    EDIT:: Didn't realize you were referencing the term within a function call after the async request -- i would suggest including the last statement within your callback.

    :)

提交回复
热议问题