简体   繁体   English

在AJAX成功中调用JSON

[英]Call JSON inside AJAX success

I want to call a json data inside my AJAX success. 我想在我的AJAX成功中调用json数据。 I'm still new on manipulating json and AJAX. 我仍然是操纵json和AJAX的新手。 Can somebody help me on how to access my json data which is from another URL? 有人可以帮助我如何访问来自其他URL的json数据吗? And I want to compare the id to the JSON data. 我想将id与JSON数据进行比较。 Here's my code so far: 到目前为止,这是我的代码:

function getCard(id){

        $.ajax({
              type: "GET",
              data: "id=" + id,
              success: function(data){

                        #call JSON data here from another URL
                        # Is it possible to call another AJAX here?

                       }
         });
    }

yes Zuma you can call another Ajax inside Success function of Ajax call. 是的Zuma你可以在Ajax调用的Success函数中调用另一个Ajax。 Below is the example: 以下是示例:

$.ajax({
        type: "post",
        url: url1,
        data: data1,
        success: function(data){                
            $.ajax({
                type: "post",
                url: url2,
                data: data2,
                success: function(data){

            });
        });
});

function getCard(id){ function getCard(id){

    $.ajax({
          type: "Get",
          url: "发送请求的地址",
          data: "id=" + id,
          success: function(data){

                    #call JSON data here from another URL
                    # if success,you can call another AJAX.
                    # Is it possible to call another AJAX here?
                    # yes!

                   }
     });
}

This code will work for you 此代码适合您

    $.ajax({
            url: "url",
            method: "post",
            data: "id=" + id,
            success:function(data) {
                // success goes here
                  $.ajax({
                       url: "url",
                       async:false,
                       method: "post",
                      data: "id=" + id,
                           success:function(json) {
                                   JSON.parse(json);

                                  // compare data and json here
                          },
                         error: function(){
                        // error code goes here
                       }
                }); 
            },
            error: function(){
                // error code goes here
            }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM