Discussions (1,327)

Livesearch JS Errors on Mainpage of Site

view profile

scottorchard says:

When the mainpage of the site loads, I get this error:

Error: [Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "" data: no]

When I type in the search box, I get this error:

Error: uncaught exception: Permission denied to call method XMLHttpRequest.open

Livesearch works fine from any other page or post except the mainpage. Also, Livesearch seems to work when I'm logged into the Site Admin. This happens in both FF on a PC or Mac and Safari, IE gives me more errors. I installed the theme and that's it.

Any ideas?

evolvefuel.com/blog/
1:24PM, 29 August 2005 PDT (permalink)

view photostream

Michael Heilemann is a group administrator Michael Heilemann says:

I have NO ideas... Anyone? Bueller? Anyone?
105 months ago (permalink)

view photostream

Myles Braithwaite says:

do you have anything that compresses css? are you using php thought cgi? is your index.php file wired?
105 months ago (permalink)

view photostream

scottorchard says:

It looks like this may be a problem with Live Archives and Livesearch. Someone started a thread in the Wordpress Support Forums:

$10 for Live Search and Live Archives

myles3 I haven't compressed css, no php through cgi. What did you mean about a wired index file?
105 months ago (permalink)

view photostream

scottorchard says:

I followed the instructions from the post here on the discussion.

This removed one of the bugs I got in IE.

Then I started to think about the site URL that is referenced in the livesearch.js.php file. It turns out that the address I entered in the Wordpress admin was this evolvefuel.com/blog, when it needed to be this www.evolvefuel.com/blog.

I'm not sure if this is related to some security setting for files using XMLHttpRequest on a server, but it solved the problem.

No JS errors in IE, FF on a PC or Mac and Safari works fine as well.

I feel kind of stupid for having this problem, but I hope this helps anyone else that may have had the same problem.
105 months ago (permalink)

view photostream

Myles Braithwaite says:

did you edit the index.php file?
105 months ago (permalink)

view photostream

FirasD says:

Summary:

LiveSearch bundled in k2 isn't allowed to open a connection under some conditions.

Versions:

WP 1.5.2; K2b1r60

Explanation:

JS is not allowed to open cross-domain connections. Your browser sees www.example.com as a different domain from example.com. In livesearch.js.php, line 107, the connection is opened thus:

liveSearchReq.open("GET", "<?php bloginfo('template_url'); ?>/livesearch.php?s=" + document.forms.searchform.s.value);

The result of bloginfo('template_url') depends on the 'WordPress Address (URI)' option in wp-admin/ Options -> General.

Steps to reproduce:

If you have www in the WordPress Address option, load your site without it, or vice versa, and watch your browser live up to expectations, making LiveSearch fail.

Possible Fixes: force a www or no www upon page load by using .htaccess or this plugin: txfx.net/files/wordpress/kill-www-kill-index-php.phps

My Fix:

Check the current address in php, adjust the call accordingly. Replace the line in question with:

liveSearchReq.open("GET", "<?php fix_request_domain(get_bloginfo('template_url')); ?>/livesearch.php?s=" + document.forms.searchform.s.value);

Add this function somewhere (I did it at the top of livesearch.js.php). Note that it is important to maintain double quotes where they are used but the single ones may be converted.

<?php
function fix_request_domain($tentative_url) {

$current_domain = $_SERVER['HTTP_HOST'];
$current_hostname = substr($current_domain, 0, strpos($current_domain, '.'));

preg_match('|http://([^\.]*)\.|', $tentative_url, $matches);
$tentative_hostname = $matches[1];

/* If only one or the other is 'www', adjust it to what the $current is */
if($current_hostname == 'www' xor $tentative_hostname == 'www') {
if($current_hostname == 'www') {
$request_firstpart = "http://www.$tentative_hostname.";
} else {
$request_firstpart = "http://";
}
$request_url = preg_replace('|http://[^\.]*\.|', $request_firstpart, $tentative_url);
} else {
/* Else just send it back; it's either ok (matching) or it's hopeless (the subdomain differences aren't just a 'www' issue). */
$request_url = $tentative_url;
}

echo $request_url;
}
?>

Possible way to make it more elegant: try to open the connection with the normal call, have the js check whether it failed, and if so, try sending it through the above php function.

Another possible way: do the url fixing in js. Probably a waste of time.

Update: had to fix this for super archives too :/ I suggest that k2 recommend forcing a www or non-www hostname whether the user typed in their address bar; redirect the one that isn't what you use in WordPress URI to the one that is.
105 months ago (permalink)

view photostream

scottorchard says:

FirasD,

Thanks for the additional explaination, I hadn't realized that my solution was rather simple and the error would still be there if someone accessed evolvefuel.com/blog instead of the URL with www in front.

I implemented your fix and everything is working fine.
105 months ago (permalink)

Would you like to comment?

Sign up for a free account, or sign in (if you're already a member).