Search code examples
jqueryajaxjquery-load

Load API results through ajax


I'm wondering that how API results can load as response comes.

similar functionality

I think using ajax from database we can get. But here from API(live results) SOAP API.

any suggestions?

EDIT

My current ajax function is

$.ajax({
    type: "get",
    url: "<?=base_url()?>search/showresults",
    cache: false,               
    data:datastring,
    beforeSend:function(){
           $('#resultloader').show();
    },
    success: function(response){
        $('#resultloader').hide(500);
        $('#showflightresults').html(response);
    },
    error: function(){                      
         //alert('Error while Sending request..');
    }
});

Thank you


Solution

  • Try setting dataType as xml and processData as false and check.

    $.ajax({
        type: "get",
        url: "<?=base_url()?>search/showresults",
        cache: false,               
        data:datastring,
        processData: false,
        dataType:"xml",
        beforeSend:function(){
               $('#resultloader').show();
        },
        success: function(response){
            $('#resultloader').hide(500);
            $('#showflightresults').html(response);
        },
        error: function(){                      
             //alert('Error while Sending request..');
        }
    });
    

    EDIT:-

    You need to iterate through php array.

    var arrayFromPHP = <?php echo json_encode($arrayPHP) ?>;
    
    $.each(arrayFromPHP, function (i, elem) {
        // do your stuff
    });