1

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^^

4

2 回答 2

0

还有其他方法。在模板中放置一个带有 id 属性(如mytemplatebase)的空 A 标签,然后您可以使用:href=bloginfo('template_url')

var urlBase = $('a#mytemplatebase').attr('href');
$.ajax({
  type: "POST",
  url: urlBase+"/file.php",
  data: dataString,
  success: function() {
    $('.done').fadeIn('slow');
  }
 });
于 2012-07-04T08:33:33.420 回答
0

在您的主题下创建一个 php 文件夹,然后以这种方式链接:

$.ajax({
  type    : "POST",
  url     : "<?php bloginfo('template_url'); ?>/php/file.php",
  data    : dataString,
  success : function() {
    $('.done').fadeIn('slow');
  }
});
于 2012-07-04T06:43:35.683 回答