![](/img/trans.png)
[英]How to access index variable in a jquery getJson call ($.getJson) during a loop?
[英]How to use getjson response variable in another getjson call within first getjson function?
我在JavaScript中使用多個getjson。 我想在另一個get json調用中使用第一個getjson調用的響應,它是一個類似於seasonID = 44567的字符串,如下面所示(在第二個getJson中使用代碼變量),但是不幸的是,我一直收到錯誤的請求錯誤。 你們能幫我解決這個問題嗎?
<script>
$.getJSON('http://www.site1.com/ok1.php&callback=?', function(data){
//$('#output').html(data.contents);
var siteContents = data.contents;
var start = siteContents.indexOf('seasons=');
var end = siteContents.indexOf('&width=385&height=230', start);
var code = siteContents.substring(start, end);
$.getJSON('http://www.site2.com/ok1.php?send="+code&callback=?', function(data){
var siteContents2 = data.contents;
document.myform2.outputtext2.value = siteContents2 ;
});
});
</script>
用這個
$.getJSON('http://www.site2.com/ok1.php?send=' + code + '&callback=?', function(data){
您在第二個getJSON
調用中引用不正確。
與其嘗試通過追加來構造查詢字符串,不如使用可選的data
參數來獲取getJSON
:
$.getJSON('http://www.site2.com/ok1.php', { send: code, callback: '?' }, function(data){
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.