[英]jquery ajax : what is the actual request sent?
當我使用jQuery Ajax時,發送到服務器的實際URL是什么? 我該如何獲得該價值? 例如,考慮以下代碼:
<script>
$.ajax({
type: "POST",
dataType: "json",
url: "response.php",
data: {name:'Smith',age:10},
success: function(data) {
...
}
beforeSend: function(){
console.log(url);
// what do I put here to see what is being sent
// I am expecting to see "response.php?name=Smith&age=10"
}
...
因此,基本上什么變量保存“ response.php?name = Smith&age = 10”。
謝謝。
沒有變量保持
response.php?name=Smith&age=10
因為您沒有將數據作為查詢字符串發送。 如果您發出GET請求,但沒有POST請求,則會發生這種情況。
您正在HTTP帖子的請求正文中發送數據。 數據是您分配給data
參數的data
。 您不需要通過jQuery的ajax方法來回傳遞它。 你已經知道了 它的:
{name:'Smith',age:10}
jQuery對數據的解釋真的重要嗎?
調用beforeSend時,將完全填充settings對象:
beforeSend: function(jqXHR, settings) {
console.log(settings.url);
console.log(settings.data);
}
$ .ajax({type:“ POST”,...})將記錄
response.php
name=Smith&age=10
並輸入:“ GET”
response.php?name=Smith&age=10
undefined
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.