最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to display Ajax returned data to HTML - Stack Overflow

programmeradmin0浏览0评论

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.

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.

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.

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.

Share Improve this question asked Oct 25, 2015 at 6:49 SaedawkeSaedawke 4716 silver badges18 bronze badges 3
  • Your not trying to use the return value of fetch_items($items_id[$i]);? what should be the final value of $content_set..? This can be resolved in many ways depending on what should be the result. "convert my ids which now is (11,2,6,8) to there names which i extract by ajax" - How are you planning to do this..? – T J Commented Oct 25, 2015 at 6:58
  • i have items table in my database which there item_id is 1,2,3,4 so the ajax will read one by one when this function fetch_items($items_id[$i]) passes the value. so the ajax response one item at a time which is the extact item name. and also i would like to display it my html table when page finishes loading or at loading time. – Saedawke Commented Oct 25, 2015 at 7:01
  • @TJ, please see my ment. – Saedawke Commented Oct 25, 2015 at 7:22
Add a ment  | 

1 Answer 1

Reset to default 3

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)
        }
    });
}
发布评论

评论列表(0)

  1. 暂无评论