附加ajax结果

时间:2018-03-26 01:49:36

标签: javascript ajax

我需要在下面打印我的函数数据,到目前为止,我试图像$.each(data.data, function(key, value) {一样将它放在循环中,也尝试直接获得结果,如data.pricedata['price']偶数{{1无效,返回+ price +

undefined

script

function myfunction(){ $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') } }); var cityname = $("#city option:selected").text(); cityname = cityname.substring(cityname.indexOf("-")+2); var statename = $("#province option:selected").text(); if(statename && cityname) { console.log(statename + " - " + cityname); $.ajax({ url: '{{ url('getcityandstate') }}/' + statename + '/' + cityname, type: "GET", dataType: "json", success:function(data) { console.log(data); // $('select[name="postchoose"]').append('<option id="postchoose" class="form-control" value="'+ price +'">'+ title +'</option>'); } }); } };

results

问题

  1. 如何打印我的数据?
  2. 更新

    这是我的控制器

    […]
    ​
    0: {…}
    ​​
    cart_amount: null
    ​​
    city: "Pandeglang"
    ​​
    created_at: "2018-03-23 12:19:28"
    ​​
    id: 6
    ​​
    price: "20"
    ​​
    state: "Banten"
    ​​
    title: "gfgg"
    ​​
    updated_at: "2018-03-23 12:24:47"
    ​​
    __proto__: Object { … }
    ​
    length: 1
    ​
    __proto__: Array []
    

0 个答案:

没有答案