Return $.get data in a function using jQuery

前端 未结 6 1340
臣服心动
臣服心动 2020-11-29 20:29

I\'m trying to call a function that contains jQuery code. I want this function to return the results of the jQuery statement. It is not working, and I\'m trying to figure ou

6条回答
  •  野性不改
    2020-11-29 21:16

    The fundamental mistake is the "asynchronous" part of AJAX. Because you don't know how long the server will take to send back a response, AJAX methods never "block" -- that is, you don't call out to the server and just sit there waiting for the result. Instead, you go on to something else, but you set up a method, called the "callback", that will fire when the results come back. This method is responsible for doing whatever needs to be done with the data (e.g. injecting it into the page).

提交回复
热议问题