0

我在 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>
4

2 回答 2

1

Use this

$.getJSON('http://www.site2.com/ok1.php?send=' + code + '&callback=?', function(data){
于 2013-02-04T04:13:02.070 回答
0

You have incorrect quoting in the second getJSON call.

Instead of trying to construct the query string by appending, use the optional data argument to getJSON:

$.getJSON('http://www.site2.com/ok1.php', { send: code, callback: '?' }, function(data){
于 2013-02-04T04:10:54.623 回答