Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Ajax - ajaxowanie linków, Dlaczego to nie działa?
Bart123
post
Post #1





Grupa: Zarejestrowani
Postów: 105
Pomógł: 0
Dołączył: 10.05.2014
Skąd: Elbląg

Ostrzeżenie: (10%)
X----


Witam. Zrobiłem coś takiego na szablonie WP Twenty Twelve, ale to ajaxowanie nie działa. Konsola Firefox wyrzuca, że metoda preventDefault(); jest przestarzała i i tak przeładowuje stronę, zamiast normalnie ajaxować link. Moje linki wyglądają w ten sposób MÓJADRES/?page_id="15".

Wydaje mi się, że z zapisem budowy linku w skrypcie może być coś nie tak.

Proszę Was o pomoc. Moglibyście to sprawdzić? Cały kod pisałem sam, wg. tutorialu - potem przerobiłem go na potrzeby swojej strony. Tyle, że w tutku działa, a u mnie nie.

CODE

$(function() {

$("column-wrap").append("<img class='ajaxloader' src='images/ajax-loader.gif' />");

var $content = $(".content"),
URL = ' ',
siteURL = "http://" + top.location.host.toString(),
$internalLinks = $('a[href]^=' + siteURL + ']'),
$ajaxSpinner = $(".ajax-loader"),
$el, allLinks = $("a");

$internalLinks.each(funtion() {

$(this).atrr("href", "#" + this.pathname);

}).click(function() {
ajaxSpinner.fadeIn();
$content.animate({opacity: "0.1"});
$el = $(this);
$(".current_page_item").removeClass(".current_page_item");
$allLinks.removeClass(".current_menu_item");
$content.load(URL);
URL = $el.attr("href").substring(1);
$content.load(URL, function (){
$el.addClass(".current_menu_item").parent().addClass(".current_page_item");
$ajaxSpinner.fadeOut();
$content.animate({opacity: "1"});
});
event.preventDefault();
return false;
});



});



Ten post edytował Bart123 24.09.2014, 11:38:33
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Turson
post
Post #2





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


[JAVASCRIPT] pobierz, plaintext
  1.  
  2. $(function() {
  3.  
  4. $("column-wrap").append("<img class='ajaxloader' src='images/ajax-loader.gif' />");
  5. var $content = $(".content"),
  6. URL = ' ',
  7. siteURL = "http://" + top.location.host.toString(),
  8. $internalLinks = $('a[href]^=' + siteURL + ']'),
  9. $ajaxSpinner = $(".ajax-loader"),
  10. $el, allLinks = $("a");
  11. $internalLinks.each(funtion() {
  12.  
  13. $(this).atrr("href", "#" + this.pathname);
  14. }).click(function(event) {
  15. ajaxSpinner.fadeIn();
  16. $content.animate({opacity: "0.1"});
  17. $el = $(this);
  18. $(".current_page_item").removeClass(".current_page_item");
  19. $allLinks.removeClass(".current_menu_item");
  20. $content.load(URL);
  21. URL = $el.attr("href").substring(1);
  22. $content.load(URL, function (){
  23. $el.addClass(".current_menu_item").parent().addClass(".current_page_item");
  24. $ajaxSpinner.fadeOut();
  25. $content.animate({opacity: "1"});
  26. });
  27. event.preventDefault();
  28. return false;
  29. });
  30. });
  31.  
[JAVASCRIPT] pobierz, plaintext

z resztą preventDefault() i return false robią to samo
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 16.10.2025 - 14:08