dsgnze6572 2017-12-05 07:13
浏览 74

如何在php中使用查询字符串传递ajax响应值

I need to pass an ajax result with query string in php. But i don't know how to assign ajax response in php variable. My code is

<script>
    function langchange()
    {
        var langs= $('#langs').val();
        $.ajax({
            type:"POST",
            url:"ajax_lang_change.php",
            data:"id="+langs,
            success:function(value){
                var data=value.split("|_,_|");
                for(var i=0;i<data.length;i++){
                    $("#cat_desc"+i).html(data[i]);
                }
            }
        });
    }
    $(window).load(function(){
        langchange();
    });
</script>

I have to assign this value to $lang_id and pass it in the following query

<a href="category.php?c_id=<?php echo $row['id']; ?>&lang_id=<?php echo $lang_id;?>"></a>

ajax-language_change.php

<?php
include 'db_connect.php';
$id = $_POST['id'];
$result = mysqli_query($link, "SELECT * FROM category AS c INNER JOIN category_language AS cl ON c.id=cl.category_id where parent_id IS NULL && lang_id='$id'");
while($row=mysqli_fetch_array($result))
{
echo $row['category_description']."|_,_|";
}

?>

The result of this script is captured in ajax and assigned in #cat_desc. I have to assign this in php variable $lang_id

Help??

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭