jquery ajax post 数据中 location.href 无效
jquery ajax post with location.href in data is not working
如果使用 location.href
(或 window.location.href
)作为数据,是什么阻止类型 POST
获得预期结果?
此代码无效(returns 什么都没有):
$.ajax({
type: "POST",
url: 'page.asp',
data: {'q': location.href},
success: function(short_link,status){
console.log('short_link = '+short_link);
console.log('status = '+status);
}
});
我确实看到 q 值在浏览器网络信息中发送,但不知何故它看起来 POST 由于 [=39= 而被重定向到 GET ]302 对象已移动 状态代码。很像那里所说的:Returning redirect as response to XHR request
但是,如果我将其更改为 data: {'q': 'to some string'}
,它会起作用。
此外,如果我将代码更改为使用 GET
(以及相应的 'page.asp'
中的代码),它也可以工作:
$.ajax({
type: "GET",
url: 'page.asp?q='+location.href,
success: function(short_link,status){
console.log('short_link = '+short_link);
console.log('status = '+status);
}
});
我认为您必须编码 url,以替换特殊字符。
我找错地方了。
page.asp
检查了导致错误的 SQL 注入函数。
如果使用 location.href
(或 window.location.href
)作为数据,是什么阻止类型 POST
获得预期结果?
此代码无效(returns 什么都没有):
$.ajax({
type: "POST",
url: 'page.asp',
data: {'q': location.href},
success: function(short_link,status){
console.log('short_link = '+short_link);
console.log('status = '+status);
}
});
我确实看到 q 值在浏览器网络信息中发送,但不知何故它看起来 POST 由于 [=39= 而被重定向到 GET ]302 对象已移动 状态代码。很像那里所说的:Returning redirect as response to XHR request
但是,如果我将其更改为 data: {'q': 'to some string'}
,它会起作用。
此外,如果我将代码更改为使用 GET
(以及相应的 'page.asp'
中的代码),它也可以工作:
$.ajax({
type: "GET",
url: 'page.asp?q='+location.href,
success: function(short_link,status){
console.log('short_link = '+short_link);
console.log('status = '+status);
}
});
我认为您必须编码 url,以替换特殊字符。
我找错地方了。
page.asp
检查了导致错误的 SQL 注入函数。