how to execute php code within javascript

前端 未结 8 1839
無奈伤痛
無奈伤痛 2020-11-30 03:47



        
8条回答
  •  被撕碎了的回忆
    2020-11-30 04:08

    You could use http://phpjs.org/ http://locutus.io/php/ it ports a bunch of PHP functionality to javascript, but if it's just echos, and the script is in a php file, you could do something like this:

    alert("");
    

    don't worry about the shifty-looking use of double-quotes, PHP will render that before the browser sees it.

    as for using ajax, the easiest way is to use a library, like jQuery. With that you can do:

    $.ajax({
      url: 'test.php',
      success: function(data) {
        $('.result').html(data);
      }
    });
    

    and test.php would be:

    
    

    it would write the contents of test.php to whatever element has the result class.

提交回复
热议问题