Saedawke
Saedawke

Reputation: 471

How to display Ajax returned data to HTML

i have these javaScript functions: function fetch_items must return some data looks like this stringvalue at a time. and the function extract_items($arr) will pass vlaue to fetch_items

    function fetch_items($id){
    $.ajax({
        url: "<?=site_url("orders/find_item")?>",
        type: "POST",
        data: {
           ajax:true,
           item_id: $id
               },
        success:function(response){
            return response;
        }
    }); 
  }

function extract_items($values) {

    var $content_set = '';
    var $items_id = $values.split(",");

    var $len = $items_id.length;

    for(var $i=0; $i<$len; $i++){
    fetch_items($items_id[$i]);

    }  
return $content_set;
}

And this is my HTML Table which i need to convert numeric IDs to item names which the ajax will return by taking the ID of the items.

enter image description here

so how to display ajax response data to the item column and convert my ids which now is (11,2,6,8) to there names which i extract by ajax.

any help please.

Upvotes: 2

Views: 8644

Answers (1)

Tasnim Reza
Tasnim Reza

Reputation: 6060

Try

function fetch_items($id) {
    $.ajax({
        url: "<?=site_url("orders/find_item")?>",
        type: "POST",
        data: {
            ajax: true,
            item_id: $id
        },
        success: function (response) {
          //return response; remove this line, async return doesn't help here
          //find the respective cell and update your div here
          $(your_element).text(response)
        }
    });
}

Upvotes: 3

Related Questions