jQuery-将值传递给php [英] jquery - passing value to php

查看:51
本文介绍了jQuery-将值传递给php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ive有2个不同的php文件. 第一个:A.php,第二个:B.php

ive got 2 different php files. first one: A.php, second : B.php

在A.php中,香港专业教育学院得到了这一行:

in A.php, ive got this line:

function altcat(id) {
            jQuery("#tvspor2").load("B.php?arupa="+id+"");
        }

让我解释一下我在A.php中的工作方式: 我在A.php中有一个链接:<a href='javascript:altcat("5")'> 因此,如果用户单击此链接,则A.php将此值发送到B.php?arupa =.它是如此简单. B.php的这一行:

let me explain what im doing in the A.php: i ve got a link in the A.php: <a href='javascript:altcat("5")'> so, if a user click this link, A.php send this value to B.php?arupa=. its so simple. and B.php has this line:

if ($_GET["arupa"]) {
echo $_GET["arupa"];
}

我在A.php中的

有这行:<div id="tvspor2"></div>因此,它显示了结果. 例如:如果用户单击链接,结果将显示为5.

in the A.php i ve got this line: <div id="tvspor2"></div> so, it shows the result. for example: if a user clicks the link, result will show 5.

这是我的问题:我可以在div中显示结果.我想将结果显示为链接.好吧,我想使用这样的结果值:<a href="-i want to display altcat(id) to here.-">test link</a>

here is my question: i can show result in a div. i want to show result as a link. well, i want to use result value like that: <a href="-i want to display altcat(id) to here.-">test link</a>

因此,我将能够根据用户的选择创建动态链接.你能给我个办法吗?我已经在这个问题上工作了将近3天:(问候

so, i will able to create dynamic links upon the user choices. can you please kindly show me a way? ive been working on this issue for almost 3 days :( regards

推荐答案

使用.ajax调用不加载,然后

Use .ajax call not load, then just

function altcat(id){
$.ajax({
   type: "GET",
   url: "B.php",
   data: "arupa=" + id,
   success: function(data){
     jQuery("#tvspor2").html(data);
   }
});
}

function okaycity(id){
$.ajax({
   type: "GET",
   url: "B.php",
   data: "bule=" + id,
   success: function(data){
     jQuery("#tvspor").html(data);
   }
});
}

function thirdlink(arupa, bule){
$.ajax({
   type: "GET",
   url: "B.php",
   data: "arupa=" + arupa + "&bule=" + bule,
   success: function(data){
     jQuery("#tvspor").html(data);
   }
});
}

如果我理解正确的问题,那就应该是. 您需要在B.php中回显HTML锚,而不仅仅是数字.

and that should be it if I have understood the question right. You need to echo HTML anchor in B.php not just number.

$arupa = intval($_GET["arupa"]);
if(!empty($arupa)){
    echo '<a href="'.$arupa.'">Link</a>';
}

$bule = intval($_GET["bule"]);
if(!empty($bule)){
    echo '<a href="'.$bule.'">Link</a>';
}

if(!empty($arupa) && !empty($bule)){
    echo '<a href="'.$arupa.''.$bule.'">Link</a>';
}

这篇关于jQuery-将值传递给php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆