Vietnam

    Nodejs.vn

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

    Error: Can't set headers after they are sent. fix làm sao vậy mọi người ?

    ExpressJS/Conect.IO
    0
    5
    3729
    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.
    • Người Lạ
      Người Lạ last edited by

      Error: Can't set headers after they are sent.
      at ServerResponse.OutgoingMessage.setHeader (http_outgoing.js:344:11)
      at ServerResponse.header (C:\Users\TRANG\Desktop\30-8-2016\learn nodeJS\buoi
      7\node_modules\express\lib\response.js:719:10)
      at ServerResponse.location (C:\Users\TRANG\Desktop\30-8-2016\learn nodeJS\bu
      oi7\node_modules\express\lib\response.js:836:15)
      at ServerResponse.redirect (C:\Users\TRANG\Desktop\30-8-2016\learn nodeJS\bu
      oi7\node_modules\express\lib\response.js:874:18)
      at C:\Users\TRANG\Desktop\30-8-2016\learn nodeJS\buoi7\demologin.js:52:15
      at Layer.handle [as handle_request] (C:\Users\TRANG\Desktop\30-8-2016\learn
      nodeJS\buoi7\node_modules\express\lib\router\layer.js:95:5)
      at next (C:\Users\TRANG\Desktop\30-8-2016\learn nodeJS\buoi7\node_modules\ex
      press\lib\router\route.js:131:13)
      at C:\Users\TRANG\Desktop\30-8-2016\learn nodeJS\buoi7\node_modules\body-par
      ser\lib\read.js:129:5
      at invokeCallback (C:\Users\TRANG\Desktop\30-8-2016\learn nodeJS\buoi7\node

      modules\raw-body\index.js:262:16)
      at done (C:\Users\TRANG\Desktop\30-8-2016\learn nodeJS\buoi7\node_modules\ra
      w-body\index.js:251:7)

      Nguyen Hien 1 Reply Last reply Reply Quote -2
      • T
        thelonglqd last edited by

        Bạn post thêm về source code của project bạn đang làm lên thì mọi ng mới giúp được.
        Lỗi này thường là do xử lý bất đồng bộ (asynchronous) không đúng dẫn đến tình trạng response.send({}) (hoặc cái nào tương tự thế) bị gọi 2 lần.

        1 Reply Last reply Reply Quote 1
        • L
          loind last edited by

          Trước mình mới tìm hiểu nên cũng dính lỗi này.
          Cách khắc phục đơn giản là dùng return sau mỗi hàm res.send hoặc res.json...
          Hy vọng sẽ giúp được cho bạn 🙂

          Nhật Nguyễn89 1 Reply Last reply Reply Quote 2
          • Nhật Nguyễn89
            Nhật Nguyễn89 @loind last edited by

            @loind tks ban

            1 Reply Last reply Reply Quote 0
            • Nguyen Hien
              Nguyen Hien @Người Lạ last edited by

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