问题描述
即时通讯将JavaScript中的一个变量传递给一行PHP包含代码以创建一个更动态的脚本。但到目前为止,我还没有设法实现这一目标。
逻辑如下:
下面的代码 - 我想用javascript变量替换'textfile.txt'。
descrip2.innerHTML =< ?php include('textfile.txt');?>;
显示:
var thisfile = [userinput];
descrip2.innerHTML =<?php include(thisfile);?>;
有关如何实现此目的的任何想法?我知道,即时通讯尝试加入客户端脚本与服务器端,但这不能以我尝试的方式完成吗?也许有一些调整?
我不想为一些应该如此直观和简单的东西写出一百个PHP脚本...... :(不是如果我可以避免它... ...
如果我理解你的问题,你不能这样做。
你可以使用ajax请求。使用jQuery你可以这样做:
var thisfile = [userinput];
$(descrip2).load(这个文件);
或者自己做ajax请求。
im trying to pass a variable from javascript into a line of PHP include code to create a more dynamic script. But so far I've not managed to achieve this.
The logic is as follows:
Looking at the below code - i want to replace the 'textfile.txt' with a javascript variable.
descrip2.innerHTML = "<?php include('textfile.txt'); ?>";
to show:
var thisfile = [userinput];
descrip2.innerHTML = "<?php include(thisfile); ?>";
Any ideas on how to achieve this? I know that im trying to join client side scripts with server side, but can this not be done the way im trying? Maybe with a few tweaks?I don't want to write a hundred php scripts for something that should be so intuitive and simple... :( not if i can avoid it...
If I understood your question you can't do like that.
you can go with ajax request. If you use jquery you can do like this:
var thisfile = [userinput];
$(descrip2).load(thisfile);
or do ajax request by yourself..
这篇关于将javascript变量传递给php代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!