我有一段的jQuery的,看起来像下面
$("<div class='creditCardDetails' id='usercurrentccbox'>
<div class='creditCard'>
<div class='cardChoice'>
<span>Choose Card Type</span>
<input name='cctype' type='radio' value='V' class='lft-field' id='visa' />
<label for='visa'></label>
<input name='cctype' type='radio' value='M' class='lft-field' id='mastercard' />
<label for='mastercard'></label><input name='cctype' type='radio' value='A' class='lft-field' id='amex' />
<label for='amex'></label>
</div>
<!--cardChoice-->
<div class='cardNumber'>
<input name='ccn' id='ccn' type='text' class='long-field' value='<?php echo MaskCreditCard($loggedInfo[ccn]);?>' maxlength='19' readonly />
</div>
<div class='cardCVV'>
<input name='cvv' id='cvv' type='text' maxlength='5' class='small-field' />
</div>
<div class='creditCardName'>
<input name='ccname' id='ccname' type='text' class='long-field' value='<?php echo $loggedInfo[ccname];?>' readonly/>
</div
<div class='cardDate'>
<input name='exp1' id='exp1' type='text' maxlength='2' class='small-field' value='<?php echo $loggedInfo[ccm];?>' readonly /><input name='exp2' id='exp2' type='text' maxlength='4' class='small-field' value='<?php echo $loggedInfo[ccy];?>' readonly />
</div>
</div><!--creditCard-->").insertAfter("#paymentCardChoice");
但你会看到它有PHP变量,如果我有这个嵌入我的PHP文件,这工作,但我想保持尽可能短的PHP文件,并将这些代码放入.js文件中,当然,我的变量只显示PHP的文本,而不是变量的自身。
我试图调用的变量已经在config.php文件中定义。
我需要使用类似的东西吗?如果是这样,我坚持如何在上面的代码中调用变量。
$.post('phpfile.php', qString, function (data) {
}, "json");
我从来不喜欢这个主意,但它肯定是有可能 – Alexander
我不知道这件事,但我认为PHP文件将在每次用户进入网页时执行。我的意思是.js不会被浏览器缓存。它会降低服务器的性能。 (我可能是错的) – lvil
你可以通过设置expires头文件使'.php.js'文件可缓存。你是否应该这样做取决于文件的内容是静态还是不稳定。 –