当url目录改变时,Ajax不向php发送请求
Ajax not sending request to php when url directory changes
现在是真的,这个查询没有被问到,最后我放弃了,因为我找不到一个可切换的答案,我的查询。
在我的apache2服务器上,我已经启用了重写规则在。htaccess文件的根目录,以持久地保持指向所有的目录和文件到某个php文件,这工作完美,但问题是ajax脚本失败时,url改变它的目录。
这是php脚本测试[…]
<?php
//now if run the test using the root directory, i get clear response,
//but as i have told u, i have enabled apache2 module and added rewrite rules to .htaccess,
//meaning that no matter hat the url is, the url will keep pointing to the same file but the problem
// is that the ajax script does not fire p the request / send.
//i dont jnow what i am doing wrong...
if(isset($_GET['test_changes'])){
echo 'the request has now reached the server';
exit;
}
?>
ajax脚本
<script>
//my ajax script is like this
//the url seen below is in the root directory.
//So briefly,how would i keep this url pointing to the same php file even if the directory changes
$.ajax({
url:'test.php?test_changes=123456789',
cache:false,
async:true,
method:'GET',
success:function(response){
console.log(response)
},
error:function(error){
console.log(error)
}
})
</script>
请使用绝对url来完成任务…见下面的代码
<?php
//it would still received the request
if(isset($_GET['test_changes'])){
echo 'the request has now reached the server';
exit;
}
?>
<script>
//i had a little trouble thinking this through but i got it working after sometime
//Now You need you ajax script url to be absolute to achieve something like that
//by prepending a forward slash character to your URL
$.ajax({
url:'/test.php?test_changes=123456789',
cache:false,
async:true,
method:'GET',
success:function(response){
console.log(response)
},
error:function(error){
console.log(error)
}
})
</script>
相关文章:
- php不是“;回声ing”;javascript正确
- 使用 JavaScript 执行一行 PHP(不包括 PHP 文件)
- Javascript/ajax 不向 php 发送空字段
- GWT HashMap.put() 不向 HashMap 添加数据
- php函数向XMPP服务器发送消息,不提供日志;不起作用
- 使用谷歌表单javascript插件而不向公众发布
- 联系表单Javascript/Ajax/PHP不是't工作
- PJAX与PHP-不工作
- 在同一行中对齐选择、输入、提交而不向下
- AJAX 调用 PHP 不起作用
- PHP不使用Jquery表单中的提交按钮
- Ember.js模型保存不向服务器发送数据
- 试图让JavaScript触发PHP脚本向表中添加一行,但它'It’不起作用
- Ajax不向PHP发送数据
- 动态创建的文本框不向php表单提交值
- Ajax会卡在beforeend阶段,不向PHP发送数据
- 检查数据库中是否存在搜索项—PHP不会输出任何内容,但仍会向数据库中添加项
- 当url目录改变时,Ajax不向php发送请求
- PHP不向JavaScript发送JSON对象
- PHP 不向 JavaScript Ajax 对象返回任何结果