Home  >  Article  >  Web Front-end  >  Guess why the function is called twice when getJSON calls the background json data_jquery

Guess why the function is called twice when getJSON calls the background json data_jquery

WBOY
WBOYOriginal
2016-05-16 17:21:111040browse

Recently, when doing front-end development, I used getJSON to call the background to retrieve json data. I found that the function in the background was called twice, and the function name was getMessages.

Multiple investigations combined with the experience of online brothers found that as long as the function name does not start with get There is no such problem.

I make a bold guess that when the json data is constructed when the request is returned, all functions starting with get are called, and then the return value is obtained and the response is constructed.

So, when the function starting with get is used as the action function, it is first called once in response to the request, and then called again to construct the response.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn