2

I have php file for adding email addresses to a newslist the file is in my wp-content/plugins directory

my file is called add_subscriber.php

i think my htaccess block this file for some reason

my htaccess file is as follow

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

when i try to call this file it somehow redirects to the 404 page.

my AJAX code

<script>
    <?php echo 'var blog_url = \''.get_bloginfo('wpurl').'\''; ?>;


function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}

function subscribeMailList(){
    email=jQuery("#ml-email").val();
    if(!validateEmail(email)){
        return false;
    }
    //jQuery("#ml-img").fadeIn(0);
    //jquery ajax request
    var url=blog_url+"/wp-content/plugins/mail-list/ajax/add_subscriber.php"

    console.log(url);

    jQuery.post(url,{emailaddress:email},function(result){
        if(result=="true"){
            $("#newsletter-form-succeeded").css("display","block");
            $("#newsletter-form").css("display","none");
        }      
    });

    //hide the form
    /*jQuery("#ml-img").fadeOut(0);
    jQuery('#ml-p').fadeOut(0);
    jQuery('#ml-p-sent').fadeIn(0);
    jQuery('#ml-form').fadeOut(0);
    jQuery('#ml-newsletterform').delay(3000).fadeOut(1000);*/
    return false;
}

</script>
Andy Jacobs
  • 15,187
  • 13
  • 60
  • 91

1 Answers1

2

If you want to use AJAX with WordPress you need to make sure the AJAX request goes through the admin-ajax.php file in the wp-admin folder.

Take a look at this article which explains in detail:

http://wp.smashingmagazine.com/2011/10/18/how-to-use-ajax-in-wordpress/

MÖRK
  • 954
  • 11
  • 31