将Ajax div内容存储在PHP变量中
I have a problem with variables. I have a website using only Jquery which means that that I use #p1
, #p02
, ..., to navigate from one page to another.
我有变量的问题。我有一个只使用Jquery的网站,这意味着我使用#p1,#p02,...,从一个页面导航到另一个页面。
I made an Ajax call which prints an id that I need in order to view my content. This id is printed in a div. The problem is that when I store the div in a variable like this:
我做了一个Ajax调用,它打印了一个我需要的id才能查看我的内容。此ID以div格式打印。问题是当我将div存储在这样的变量中时:
$variable="<div class='something'></div>";
I can echo the variable but CAN'T use it in order to make queries. I know this is but programming but if I use sessions instead the identity didn't updated at all from page to page because of the using of #p01
instead of p1.php
.
我可以回显变量,但不能使用它来进行查询。我知道这只是编程但是如果我使用会话而不是因为使用#p01而不是p1.php而在页面之间没有更新身份。
I also added the ajax.js file if this help you in order to advise me. The ajax.js file sends an identity to Ajax_page.php then I store this $_POST variable in a SESSION and then I echo this varible in Ajax_page.php. When i echo this variable it also printed in the div which is in the Show_content_page.php. I want the contents of that div. I want to use this div contents(identity) in order to make my php queries. Thats all.
我还添加了ajax.js文件,如果这有助于你建议我。 ajax.js文件向Ajax_page.php发送一个标识然后我将这个$ _POST变量存储在一个SESSION中,然后我在Ajax_page.php中回显这个变量。当我回显这个变量时,它也会打印在Show_content_page.php中的div中。我想要那个div的内容。我想使用这个div内容(标识)来进行我的php查询。就这样。
Is there any way to make the $variable
useful?
有没有办法让$变量有用?
Here are the to sample files
以下是示例文件
Ajax_page.php
<?php
session_start();
if(!empty($_POST['show_an_anetoix']) ){
$_SESSION['anetoix_id']=$_POST['show_an_anetoix'];
}
echo $_SESSION['anetoix_id'];
?>
Show_content_page.php
<div id="p1" >
<?php
$variable="<div class='something'></div>";
echo $variable; //no problem
function_test($variable); //problem
?>
</div>
The ajax.js
/* Pass data with changePage */
$(document).on("pageinit", "#p1", function () {
$(document).on('click', '.anetoix_class', function(){
$.mobile.pageContainer.pagecontainer("change", "#p02", {
stuff: this.id,
transition: "flip"
});
});
});
/* retrieve data and run function to add elements */
$(document).on("pagebeforechange", function (e, data) {
if (data.toPage[0].id == "p02") {
var stuff = data.options.stuff;
var data = {"show_an_anetoix": stuff,};
$.ajax({
type: "POST",
url: "../show_an_anetoix.php",
data: data,
success: function(response)
{$(".show_an_anetoix").html(response);}
});
}
});
1 个解决方案
#1
1
Not 100% sure what you mean. Are you asking, can you use a PHP variable in ajax? If so, I would do something like this:
不是100%肯定你的意思。你问,你能在ajax中使用PHP变量吗?如果是这样,我会做这样的事情:
<script>
$ajax_variable = "<?php echo $php_variable; ?>";
</script>
更多相关文章
- 如何递归将特色图像应用于Wordpress中的子页面?
- phpnow1.5.6如何设置404错误页面?
- Contenteditable / Jquery / Ajax / PHP / mysql - 无法识别URL
- Thinkphp中怎么接收GET变量?
- 海图没有显示任何东西,只是空白的html页面
- PHP变量类型+整型类型细节
- 注意:未定义的变量:after_widget in ... wp-content / plugins / w
- 使用GMail SMTP服务器从PHP页面发送电子邮件
- php 获取当前页面url路径