How can I pass a PHP variable to javascript?

前端 未结 4 1088
失恋的感觉
失恋的感觉 2020-12-21 05:44

I want to use a PHP variable as a javascript variable - specifically I want to user the PHP variable session_id(); and use this as a javascript variable.

&l         


        
4条回答
  •  天命终不由人
    2020-12-21 06:28

    That's just fine. Be sure that if the variable you're echoing is a string that you put quotes around it and escape any quotes, newlines, etc. inside it -- e.g., make sure it really gets output as a valid JavaScript string literal. Also, don't forget the var before js_var.

提交回复
热议问题