如何在调用PHP服务器端代码时使Ajax调用的路径动态
如何在Ajax调用中使路径成为动态的,当我在本地运行代码时,它只能在URL路径为“/WebsiteFolder/assets/mail/contact_me.php”时工作,而当它托管在cPanel上时,它只能在URL路径为“/assets/mail/contact_me.php”时工作,如何使路径成为动态的如何在调用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",
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”