为什么ajax post不能加载页面时,使用短url
Why ajax post can not load page when use short url?
为什么ajax post不能在使用短url时加载页面?
当我使用短URL test.php
在ajax的帖子像这样
<script>
function send_username_value_for_check_available() {
$.ajax
(
{
url: 'test.php',
type: 'POST',
data: $('#username_send_value_fid').serialize(),
cache: false,
success: function (data) {
$('#mySpan_username').show();
$('#mySpan_username').html(data);
}
}
)
}
</script>
i will get error
XMLHttpRequest cannot load https://example.com/test.php. Response for preflight is invalid (redirect)
但是当我使用完整的URL https://www.example.com/test.php
时,它工作得很好。
如何在ajax post中使用短URL ?
我认为这与AJAX与短URK问题无关…
你必须允许CORS从你的服务器为这个域名,它将工作
http://enable-cors.org/server_php.html您的短URL test.php
解析为example.com/test.php
example.com
和www.example.com
被视为不同的结构域。因此ajax请求被视为跨域调用。
尝试在脚本中使用Access-Control-Allow-Origin
头授权example.com
和/或www.example.com
(您应该避免允许'*')。使用php:
header("Access-Control-Allow-Origin: https://example.com");
更多信息:
-"CORS响应头"可能是搜索关键字,以帮助您在这个主题。
-也看看这个答案:https://stackoverflow.com/a/8689332/3872061
相关文章:
- JavaScript 中的 POST url 被注释掉了
- 使用 POST 方法通过 ajax 发送的数据在发送到服务器之前是否必须进行 URL 编码
- Angular 2:HTTP Post Request,带有URL参数和正文类型参数
- 使用表单和POST方法通过Javascript获取URL参数
- 如何在不更改URL的情况下使用HTTP方法POST
- qoxdoo:POST方法,不在URL中显示参数
- 如何在NodeJS中对POST请求进行url解码
- jQuery/PHP-POST-Forbidden(403)当试图在我的JSON数据中发送完整的URL时
- 当使用预先签名的POST url将文件上传到AWS S3时,设置随机文件名
- 获取链接帖子使用脚本“data:post.url”博主不起作用
- jQuery $.ajax post getting referer url for error debugging
- XMLHttpRequest POST 请求到当前 URL 的有效 URL 字符串
- AngularJS在使用method:POST时$resource调用错误的API URL
- 使用Joomla的jRoute库时POST URL的问题
- 如何在 ASPX 页的代码隐藏中使用 POST 设置图像的 url
- Ajax Post请求总是运行错误功能,尽管卷曲到相同的url工作正常
- Ajax 无法使用 jquery url post 方法
- 从javascript到php的动态url POST
- Node.js URL POST rewrite
- Ajax POST调用不能正常工作,返回错误代码0,即使url POST成功