How to return Javascript as partial response?

前端 未结 1 1962
梦毁少年i
梦毁少年i 2021-01-21 06:08

As response to an Ajax-request I want to return Javascript that is executed on the client immediately. I tried it like this but it doesn\'t work:



        
相关标签:
1条回答
  • 2021-01-21 06:33
    writer.write("alert(’Works!’);");
    

    Curly quotes are not a valid string delimiter in JS. Use straight quotes.

    writer.write("alert('Works!');");
    

    Unrelated to the concrete problem, based on your question history you're using PrimeFaces, or at least familiar with it. In that case, just use RequestContext#execute() instead of this mess.

    0 讨论(0)
提交回复
热议问题