It's me again. And AJAX / jQuery. In general, I read the links in the internet and I can not understand some things. Namely - how can I make it so that now let's say the site mysite.ru is open? There is a link on the site. It is already formed and leads to mysite.ru/news.php?p=1 What I need is that without reloading the page, the parameter that is in p (which is "1") is transmitted using the ajax php script (news.php) and there I am already would process further all. That is, if anything, I could pass 2 if I wrote in the address bar? P = 2, etc.
How can I get some GET to pull it and all the links should be written in the address bar? I know that ajax has a data parameter. But I do not understand how it works. So far, for the night itself, unfortunately, I have not tried it myself, as they say, but I just can’t even understand it for now. The guessing game also does not really want to play.
- If you're talking about the basics like: javascript.ru/blog/gordon-freeman / ... or sql.ru/forum/actualthread.aspx?tid=753608 or even such jquery.page2page.ru/index.php5/... that of them about the line addresses are not clear nifiga. - DizzWebS
2 answers
As I wrote here , everything is simple, and in the link you can simply add the news id
<a href="#" id="moren" onclick="LoadNews('id_новости');return false;">Показать всю новость</a>
there is also a way to change the url in html5, here is the article or here is another interesting article on Habré about how to navigate on Twitter
ZY Somehow I did this myself, eventually I got a bunch of bugs, finally I drank this navigation and did the usual, reducing the weight of pages from a heap of unnecessary elements, as practice has shown, if there is no player or duplicate pages on the site, then on Twitter There is nothing, it is easier to debug the pages, reducing their weight.
- Here are many similar examples. And add news id to the link - do you mean instead of "#"? I already managed to read about the work with the address bar, then this topic came out of those readers) It's just that the question about the paginator on ajax (I have a conclusion on three news) and the address line are more interesting. Just actually my site is one page, stuffed with all sorts of scripts. It looks not loaded, but I would still like a beautiful implementation of the same news for quick access via a link or page to them (where there are three). True, I thought it should have been easier to implement a bit :) I 'll try on everyone :) - DizzWebS
- I walked on an Internet and apparently everything is just done through history. So far, the truth also doesn’t quite understand how)) you want to have something to do with hash, although it seems that you will have to touch it somehow to finish the site for a donkey. - DizzWebS
- oneTo work with a donkey, it is necessary to have a hash navigation, and the rest can be done through history. - Nov
- Right) When I wrote, I forgot about the hash :) - DizzWebS
Made. At once I will make a reservation that the code ONLY substitutes the URL and loads it into the necessary div from the database, i.e. if you go to this URL by inserting it into the address bar, nothing happens. Plus, there are no “foolish” checks, and the “back” button is still not working, and hasn’t yet removed the address line from the required part of the address. Cheto still does not work there, but I did the functionality that I personally needed at the moment. Here is the code:
PS In a donkey, even 9 does not work (!)
index.php
<div id="left_side"><a href="/?p=1" onclick="getpage(event, this); return false">TEST!!!</a></div>
ajax.php
function getpage(event, param) { //функция, записывающая значение p из адреса mysite.ru/?p=1,2,3 и т.д. var url=param.href; var urlarr=new Array(); urlarr = url.split('='); var idx=urlarr[1]; openpage(idx); event.preventDefault(); }; function openpage(idx) { $.ajax({ type:"GET", url:"/engine/news.php", data: {"idx":idx}, cache: false, success: function(test){ $('#right_side').html(test); history.pushState(null,null, "?p="+idx); } }) return false; };
Well, news.php
<?php include "dbauth.php"; $idx = intval($_GET['idx']); $query = "select * from site.news where id='$idx'"; $result = mysql_query($query) or die(mysql_error()); $row=mysql_fetch_array($result); echo $row['news_full']."<br>"; echo '<a href="#" id="testc">CLOSE AND BACK</a>' //ЭТА ССЫЛКА будет убирать инфу из дива и отсекать тот добавленый адрес в адресной строке. ?>