Vietnam

    Nodejs.vn

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Groups
    • Search

    Lỗi respond data

    ReactJS
    0
    4
    903
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      Công Toàn Lê last edited by

      Mình viết hàm lấy API JSON dùng Promise (resolve, reject) mà cứ bị reject hoài không hiểu lý do tại sao. Anh em check lỗi giúp mình nha. Tạ ơn anh em nhiều lắm

      File JSON: {"id":3,"url":"http://localhost:8000/api/v1/feeds/3/?format=json","user":{"id":2,"username":"lecongtoan2","first_name":"Tran","last_name":"Haong"},"date":"2017-08-31T04:56:32.785000Z","post":"lecongtoan2 has joined the network.","likes":0,"comments":0,"comment_list":[]}

      getFeedDetail (id) {
      baseUrl: 'http://localhost:8000/api/v1/',
      return new Promise((resolve, reject) => {
      request.defaults.baseURL = this.baseUrl
      request.get(feeds/${id}/).then(response => {
      const data = [...response.data][0]
      if (response.status === 200 && response.data.length > 0) {
      const filtered = {
      post: data.post
      }
      resolve(filtered)
      } else {
      console.log('Failed')
      reject(response)
      }
      })
      })
      }
      }

      1 Reply Last reply Reply Quote 0
      • tuanquynet
        tuanquynet last edited by tuanquynet

        @Công-Toàn-Lê
        Đoạn code bạn gởi bị lỗi cú pháp nhiều quá. Bạn nên gởi đoạn code chính xác để người khác còn giúp được.

        papa elf

        1 Reply Last reply Reply Quote 1
        • C
          Công Lương Ngô last edited by Công Lương Ngô

          Mình nghi ngờ vấn đề nằm ở chỗ này:

          baseUrl: 'http://localhost:8000/api/v1/',
          return new Promise((resolve, reject) => {
          

          Bạn thử đổi thành:

          baseUrl = 'http://localhost:8000/api/v1/';
          return new Promise((resolve, reject) => {
          

          Thử xem code có chạy không nhé

          1 Reply Last reply Reply Quote 1
          • C
            Công Toàn Lê last edited by

            Cảm ơn các bạn. mình đã fix dc rồi nha

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            $(document).ready(function () { app.coldLoad(); }); }