[英]ajax not working for getting url value stored in a constant
hello everyone i am beginner in js/ajax and php so sorry in advance if u feel my question is a childish one i am have define the site url in my config file 大家好,我是js / ajax和php的初学者,所以如果您觉得我的问题很幼稚,请在此先抱歉,我已经在我的配置文件中定义了网站网址
config.inc.php config.inc.php文件
$config['siteurl']= "http://".$_SERVER['SERVER_NAME']."/abc"; $ config ['siteurl'] =“ http://”。$ _ SERVER ['SERVER_NAME']。“ / abc”;
define('siteurl', $config['siteurl']); define('siteurl',$ config ['siteurl']);;
now on my page em including the config file and i checked i am greeting the url value but what i want is to print the value in window.location.heref="" here my function 现在在我的页面上包括配置文件的em上,我检查了我在问候url值,但是我想要的是在window.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" }); } }); });
if i use window.location.href= " http://localhost/abc/abc.php "; 如果我使用window.location.href =“ http://localhost/abc/abc.php ”; it works fine
它工作正常
Change 更改
window.location.href = <?php echo (siteurl) ?>;
To 至
window.location.href = "<?php echo (siteurl) ?>";
You need to wrap the output of the constant in quotes for JS to pick it up as a string (which it requires for a URI) 您需要将常量的输出用引号引起来,以便JS将其选择为字符串(需要URI)。
"'"+<?php echo (siteurl) ?>+"'"
使用它可能会正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.