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



如何在Ajax调用中使路径动态,当我在本地运行代码时,它只能在URL路径为"时工作/网站文件夹/assets/mail/contact_me.php">,并且当它托管在cPanel上时,它只能在URL路径为"strong>"时工作/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"

你会有

"assets/mail/contact_me.php"

最新更新