为什么第二个$ _GET变量被删除?

时间:2013-11-28 23:25:58

标签: javascript php jquery html get

好的,所以我正在建立一个网站,它使用了相当多的JQuery和JavaScript,因为它使网站更容易使用,而且我可以使用索引页面作为页面布局和所有其他页面来存储页面数据。所以这就是我正在做的事情。

我尝试转到页面http://example.com/index?page=ItemSearch?item=Sword&sortby=Damage

但是一旦页面加载,它就会删除最后一个块,只加载http://example.com/index?page=ItemSearch?item=Sword

这是我的页面名为ItemSearch.php的代码(减去布局,简而言之就是PHP代码):

<?php
$item = $_GET['item'];
$sortby = $_GET['sortby'];
echo $sortby;//I put this in here to see if it would print something as the value, it doesn't.
if(!isset($item)){
echo 'What item are you looking for?<br><br>';
//Form here
}else if(isset($sortby)){//Doesn't recognize that item is or was set because it's no longer there
include('grabdata.php?item='.$item.'&sortby='.$sortby);
echo "Item: ".$item." Sort by ".$sortby;
}else{//Does however notice that the item was set
include('grabdata.php?item='.$item);
echo "Item: ".$item;//Prints "Sword" as it should
}
?>

这是索引页面,正如我之前所说的基本上只是布局(也缩短了以删除任何个人或不需要的信息):

<!doctype html>
<html lang="en">
<head>
<script type="text/javascript" language="javascript" src="funcs.js"></script>//JavaScript functions page
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>//Including JQuery in order to use JQuery functions
</head>
<body>
<div id="content">
<?php
echo '<script>loadPage("' . $page . '");</script>';//Loading whatever the $_GET variable for 'page' is set to, in this case $_GET['page'] = "ItemSearch"
?>
</div>
</body>
</html>

现在我当然应该展示我的JQuery&amp;这里的JavaScript函数是我的funcs.js文件(未经编辑):

function loadPage($link){
$('#content').html('<br><br><img src="Load.gif"/>');//Shows a loading bar so people know the page is loading
$('#content').load($link+'.php');//JQuery loads pages onto the #content div
window.history.pushState("", "", '/index?page='+$link);//If I comment this line out, it does not remove the second $_GET variable from the address bar... However the website still does not recognize that the second $_GET variable is there? Idk why :/
}

function loadTitle($link){
$(document).attr('title', "Website name here - "+$link);//Just changes the name of the page
}

我真的不明白为什么它会完全删除第二个$ _GET变量,也不理解为什么它在那里时不能识别它。希望上面显示的评论对一些人有所帮助。我真的很感激我能得到的任何帮助。谢谢!

0 个答案:

没有答案