如何在ajax的外部JavaScript文件中使用php变量?

问题描述:

基本上,我想通过ajax在外部Js文件中使用php variavle。例如:如何在ajax的外部JavaScript文件中使用php变量?

在使用example.php文件

<?php 
$a="123" 
//and then I want to call a show() function through a onclick event later 
<xxxxxxxxxxxxx...... onclick="show()">; 
?> 
在另一个example2.js

文件中,有一个功能

show() 
{ 
    var b 
    // I want to assign $a's value to this variable b here.=> b=a 

    //but I only want to do this way by using ajax. 

} 

有没有人能告诉我该怎么做?谢谢。

您是否尝试将ajax_object.responceText插入到a中的值中,然后使用javascript获取它?