大家好,我是JS/AJAX和PHP的初学者,如果您觉得我的问题是一个幼稚的问题,我已经定义了我的配置文件中的站点URL
config.inc.php
$ config ['siteurl'] =" http://"。$ _ server ['server_name']。
define('siteurl',$ config ['siteurl']);
现在在我的页面上包括配置文件,我检查了我在问候URL值,但是我想要的是在window.location.location.heref ="此处打印值
$('#form_id').submit(function (e){
var $this = $(this);
e.preventDefault();
$.post($this.attr('action'), $this.serialize(), function (responseData) {
if(responseData == "success"){
window.location.href = <?php echo (siteurl) ?>;
}
else if (responseData){
swal({
title: "Error!",
text: responseData,
type: "error",
confirmButtonText: "ok"
});
}
});
});
如果我使用window.location.href =" http://localhost/abc/abc.php";它可以正常工作
"'"+<?php echo (siteurl) ?>+"'"
使用此功能可以正常工作
更改
window.location.href = <?php echo (siteurl) ?>;
to
window.location.href = "<?php echo (siteurl) ?>";
您需要将常数的输出包装在引号中,以使JS将其作为字符串(需要URI需要)