hey guys, I really really need your help. I have just no idea why that happens.
I’m trying to load a wordpress page with the jquery $ajax method. However my browser is crashing all the time when I try to load this page.
I’ve build a kind of ajax search that requests a wordpress page when typing inside of an input field. This is my code.
jqXHR_Old = $.ajax({
url: "searchmap", // searchmap means mydomain.com/searchmap
dataType: "html",
success: function (data) { ...
The weird thing is: When i change the url to a static page like url: "searchmap.html"
everything works fine. As soon as I choose the dynamically generated WordPress Template “searchmap” the ajax response throws “301 Moved Permanetly” messages.
This is my template that works just fine when I call it in the browser…
<div>
<h3>Pages</h3>
<ul>
<?php wp_list_pages('title_li=&depth=0&exclude='); ?>
</ul>
<h3>Posts</h3>
<?php $first = 0;?>
<ul>
<?php
$myposts = get_posts('numberposts=-1&offset=$first');
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<h3>Categories</h3>
<ul>
<?php wp_list_categories('title_li=&orderby=name'); ?>
</ul>
</div>
Any idea why Firebug or Fiddler responds with “301 Moved Permanently” errors when I load this page with $.ajax() ?
My browser keeps crashing, even though I abort each ajax request when typing again. So there are never happening multiple ajax requests.
$.ajax requests mydomain.com/searchmap and mydomain.com/searchmap requests the server for all pages, posts and cats.
Any ideas? I’m completely clueless!
I’m guessing the page your calling executes an wp_redirect with a 301 response somewhere.
Dont really have an answer for you but maybe you can try the following. Ajax does not know what type of page your calling from and there might be some strange query_vars loaded that trigger a redirect.
Ajax call action.
If you want to use wp_ajax you will need to add some more.
Im using POST variable for my ajax script so it alawys runs in admin, if you write the jquery script with GET you will need to call the norpriv function outside admin. (just figured this out now)
U might have to fix the script here and there, it’s just an offhand example.
the function has to return the data you need. For example: