dongli7870 2018-03-24 09:32
浏览 635

如何从laravel API中提取JSON对象数据?

I want to extract JSON data from laravel using JQUERY but the result is always undefined.

this is the json code I've got:

{"data":{"id":1,"title":"glove hard","code":"0102","category":"glove"}}

and this is the js code:

        $('#show').click(function(){

        $.ajax({
            url: 'example.com/api/product/1',
            method: 'GET',
            dataType: 'json',
            success: function(data){
                $('#result').text(data.category)
            }
        })
    })
  • 写回答

3条回答 默认 最新

  • douan0729 2018-03-24 10:27
    关注

    Use the $.parseJSON which parse the well formatted json string into js object. Your success callback will be

    success: function(data){
                    var obj = $.parseJSON(data);
                    $('#result').text(obj.data.category)
                }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流