如何将我的链接变为变量?

时间:2015-10-31 16:10:24

标签: javascript php html mysql

我收到了这些文件:
更新脚本:

<script>
    function TradeURLTimer() {
        setInterval(function(){
            jQuery.ajax({
                url: "assets/cores/check_username.php",
                data:'TradeURL='+$("#TradeURL").val(),
                type: "POST",
                success:function(data){
                $("#username-availability-status").html(data);
                },
                error:function (){}
            });
        }, 3000);
    }
</script>

我的check_username.php:

<?php
// Variables to connection
$mysql_hostname = "localhost";
$mysql_user = "*******";
$mysql_password = "*********";
$mysql_database = "**********";
$prefix = "";
// Create connection
$conn = mysql_connect($mysql_hostname, $mysql_user, $mysql_password);
$connect = mysql_select_db($mysql_database, $conn);

$TradeURL=$_POST['TradeURL'];
$count_TradeURLs = mysql_num_rows(mysql_query("SELECT * FROM users WHERE TradeURL='$TradeURL'"));
switch ($count_TradeURLs) {
    case "0":
        ?>
        <section class="feed-item col-md-2 pull-left">
            <div style="padding-top: 5px;" class="icon">
                <i class="fa fa-check color-green"></i>
            </div>
        </section>
        <?php
        echo $TradeURL;
        break;
    case "1":
        ?>
        <section class="feed-item col-md-2 pull-left">
            <div style="padding-top: 5px;" class="icon">
                <i class="fa fa-remove color-red"></i>
            </div>
        </section>
        <?php
        break;
}
?>

我插入的文字$_POST['TradeURL'] = = https://steamcommunity.com/tradeoffer/new/?partner=53756765&token=bnsKYKib但是当我要求check_username.php回显变量$TradeURL时,它就是只有https://steamcommunity.com/tradeoffer/new/?partner=53756765

所以有些东西正在删除链接的最后一部分:
“&amp; token = bnsKYKib”
为什么会发生这种情况?我无法弄清楚。我试图将它转换成一个字符串并拆分它,但仍然是相同的结果......

1 个答案:

答案 0 :(得分:1)

正如@leonardo_palma指出的那样,您的TradeURL变量正在被PHP解析。 您必须对其进行编码以将其发送到其他页面,然后对其进行解码。 以下是如何做到这一点:

更新脚本:

if ($('.sticky-target-menu').hasClass('collection-menu-open')){
    $('#logo-img img')
    .css( {'height': '55px', 'position': 'relative', 'top': '10px',} )
    .attr('src','https://cdn.shopify.com/s/files/1/0893/1740/t/2/assets/logoblack2.png?16348450756183240677');
      $('.livery-search-button')
              .attr('src','http://cdn.shopify.com/s/files/1/0893/1740/t/2/assets/icon-search.png?2506340321008419925');

}

check_username.php:

// ...
data: 'TradeURL='+encodeURIComponent($("#TradeURL").val()),
// ...