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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
    • ¥15 画两个图 python或R
    • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
    • ¥15 八路抢答器设计出现故障
    • ¥15 opencv 无法读取视频
    • ¥15 按键修改电子时钟,C51单片机
    • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
    • ¥20 5037端口被adb自己占了
    • ¥15 python:excel数据写入多个对应word文档