Calling PHP scripts from Javascript without leaving current page

前端 未结 7 1397
别跟我提以往
别跟我提以往 2021-01-18 14:57

I\'m having some trouble calling PHP scripts from Javascript without leaving the current HTML page (if it is at all possible). I understand it is possible using AJAX, althou

7条回答
  •  忘掉有多难
    2021-01-18 15:34

    Just happened to have the same issue, so I came up with something like that. All you have to do is add the code you need, and assign the do_the_script function to the onclick event.

    
    

    As you may have noticed, the code that "calls" the address is executed every 1 second. This, is to ensure that the call is made enough times so as to get a single positive answer, call the doneHandler and clear the interval afterwards. If you believe that your server can respond faster or slower you should change those milliseconds accordingly.

提交回复
热议问题