如何使用jquery链接到Wordpress插件中的PHP文件

时间:2012-07-04 06:33:50

标签: php jquery wordpress

我正在尝试编写一个wordpress插件。基本上它是一个通过jQuery发送到PHP文件的Form。 (我使用了this Tutorial:中显示的代码)不幸的是我不知道如何链接到jQuery中的PHP文件。问题是,我在Wordpress中启用了SEO友好URL,所以当我使用以下代码时:

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

服务器假定PHP文件位于http://seofriendlylinktomypost/file.php。 希望有人可以帮助我,并提前感谢=)。 对不起我糟糕的英语,我希望你明白一切^^

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

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