简体   繁体   English

Wordpress - 包含 php 文件并用 ajax 调用它

[英]Wordpress - include php file and call it with ajax

I have added a javascript code in a PageBuilder of a page in my wordpress site.我在 wordpress 站点的页面的 PageBuilder 中添加了一个 javascript 代码。 This code will do an ajax call to a PHP file, like this:此代码将对 PHP 文件执行 ajax 调用,如下所示:

var check = function(a) {
$.ajax({
    url: 'dwload.php',
    type: 'POST',
    data: {a:a},
    success: function(data) {
        if(data === 'NOK'){
            alert('OK');
        }else{
            window.open(data);
        }
    }
});
};

i modified the index.php file in the root folder:我修改了根文件夹中的 index.php 文件:

include '/dwload.php';

and added the dwload.php file in the root folder.并在根文件夹中添加了 dwload.php 文件。

but when i call the ajax function, i get the error 404, not found.但是当我调用 ajax 函数时,我收到错误 404,未找到。

how can i solve the problem?我该如何解决问题?

Thank you in advance.先感谢您。

I don't have reputation enough to comment, so I will answer, I think you just first check the permissions of file.我没有足够的声誉发表评论,所以我会回答,我想你只是先检查文件的权限。 The server must be able to execute thee file, and this can make some trouble.服务器必须能够执行您的文件,这可能会带来一些麻烦。 You can see more here . 你可以在这里看到更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM