How to link to a PHP file inside a WordPress Plugin using jquery

I’m currently trying to write a wordpress plugin. Basically it’s a Form that is send to a PHP file via jQuery. (I’ve used the Code shown in this Tutorial:) Unfortunately I don’t know how to link to that PHP file inside jQuery. The Problem is, that I have enabled SEO friendly URL’s in WordPress, so when I’m using the following Code:

$.ajax({
  type: "POST",
  url: "file.php",
  data: dataString,
  success: function() {
    $('.done').fadeIn('slow');
  }
 });

The Server assumes the PHP file to be located at http://seofriendlylinktomypost/file.php .
Hopefully someone can help me and thanks in advance =).
I’m sorry for my awful English, I hope you understood everything^^

Related posts

Leave a Reply

2 comments

  1. Create a php folder under your theme and then link in this way:

    $.ajax({
      type    : "POST",
      url     : "<?php bloginfo('template_url'); ?>/php/file.php",
      data    : dataString,
      success : function() {
        $('.done').fadeIn('slow');
      }
    });
    
  2. There is also other way. Place an empty A tag with an id attribute (like mytemplatebase) and href=bloginfo('template_url') in the template, then you can use:

    var urlBase = $('a#mytemplatebase').attr('href');
    $.ajax({
      type: "POST",
      url: urlBase+"/file.php",
      data: dataString,
      success: function() {
        $('.done').fadeIn('slow');
      }
     });