Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在调用PHP服务器端代码时使Ajax调用的路径动态_Php_Ajax - Fatal编程技术网

如何在调用PHP服务器端代码时使Ajax调用的路径动态

如何在调用PHP服务器端代码时使Ajax调用的路径动态,php,ajax,Php,Ajax,如何在Ajax调用中使路径成为动态的,当我在本地运行代码时,它只能在URL路径为“/WebsiteFolder/assets/mail/contact_me.php”时工作,而当它托管在cPanel上时,它只能在URL路径为“/assets/mail/contact_me.php”时工作,如何使路径成为动态的 $.ajax({ url: "/WebsiteFolder/assets/mail/contact_me.php", type: "POST", d

如何在Ajax调用中使路径成为动态的,当我在本地运行代码时,它只能在URL路径为“/WebsiteFolder/assets/mail/contact_me.php”时工作,而当它托管在cPanel上时,它只能在URL路径为“/assets/mail/contact_me.php”时工作,如何使路径成为动态的

$.ajax({
url: "/WebsiteFolder/assets/mail/contact_me.php",
type: "POST",
data: {
    name: name,
    phone: phone,
    email: email,
    message: message,
},
cache: false,
success: function () {
    // Success message
  
},
error: function (xhr, status, error) {
    // Fail message

},
complete: function () {
    setTimeout(function () {
        $this.prop("disabled", false); // Re-enable submit button when AJAX call is complete
    }, 1000);
},
}))

使用

删除前面的
/

而不是

“/WebsiteFolder/assets/mail/contact_me.php”

你会有

“资产/mail/contact_me.php”