开发者

jquery and remembering url attributes?

开发者 https://www.devze.com 2022-12-15 10:22 出处:网络
In index page I manage categories by just putting in url /?cat=mycat attribute. Now, w开发者_StackOverflow社区hen user clicks a link which start jQuery update. First inserting data in SQL and if succe

In index page I manage categories by just putting in url /?cat=mycat attribute. Now, w开发者_StackOverflow社区hen user clicks a link which start jQuery update. First inserting data in SQL and if success then $("#indexPage").load('updateIndexPage.php') where contains query of index elements from database.

Now, I can't get that to fetch urls attributes (in this case this ?cat=mycats). I have in that updatefile $cat = $_GET['cat']; but it doesn't work??

So what is happening is that when user is some of my cats, and click link after that query is not showing that category stuff where user was.. :)

well that's messy.. :)


Your call to $.load() isn't actually passing any GET variables to the server. Review the documentation for $.load() again: http://docs.jquery.com/Ajax/load

$.load( url, [data], [callback] )

Note the second parameter is where you would pass in your values. Note also that if you pass these variables using $.load(), they will not show up as GET on the server, but instead POST, as indicated by the documentation:

...will POST the additional parameters to the server and a callback that is executed when the server is finished responding.

$("#feeds").load("feeds.php", {limit: 25}, function(){
   alert("The last 25 entries in the feed have been loaded");
});

To account for this difference, simply change your PHP code to one of the following:

$cat = $_POST["cat"]; // looks for a 'cat' variable in POST
$cat = $_REQUEST["cat"]; // looks for a 'cat' variable in POST or GET


Try passing the window get variables to the Ajax URL:

$("#indexPage").load('updateIndexPage.php' + window.location.search);
0

精彩评论

暂无评论...
验证码 换一张
取 消