WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

(Cross-posted from stack overflow)

I am building a WordPress plugin. The plugin works beautifully on one site.

But on every other site I've tried so far one of the resource files used it getting a 404 (Not Found) error in the console. If I post the url, displayed in the console as not found, in the address bar the file is accessible.

The site it works on is not in a root directory, while one it doesn't work on is on the same server, in the root directory and is a multisite installation. I've tried it on other servers, and sometimes it works, on others it doesn't'. I'm baffled by what might cause this... Any feedback would be appreciated.

The following code is posted using a action into the header of a page:

echo '<script type="text/javascript">
            var lpOnComplete = function(response) {

                // do more processing

            function lpStart() {
                $.post("'.plugin_dir_url(__FILE__).'filename", {varname: "'.$value.'"}, lpOnComplete, "json");

The URL that is said to not exist is the one that is posted to in function lpStart().

Interestingly, when it doesn't work I get the following error in the console as the page loads.

GET http://example.com/undefined 404 (Not Found)

Thank you in advance.

share|improve this question
up vote 0 down vote accepted

See the Codex page on using AJAX in Plugins properly and use wp_localize_script to pass data from php to javascript.

share|improve this answer
Sweet! Will definitely check this out! – rpophessagr Jan 15 '12 at 14:55
So the AJAX in Plugins link talks about using ajax in the admin area, I'll be needing it in on the front-end. Do you know if it would work there? – rpophessagr Jan 15 '12 at 21:57
@rpophessagr - it's on that same page, scroll down to ajax on the viewer facing side section. – Milo Jan 16 '12 at 0:17
This article explains everything. Thanks for pointing me in the right direction. – rpophessagr Jan 16 '12 at 3:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.