jQuery .post()未执行


                    

我通过jQuery进行了以下AJAX调用:</ p>

  // var upload =一些JSON数据
$ .post('/ videos / upload',上载);
</ code> </ pre>

这是express.js API的一部分,用于处理请求:</ p>

  app.post('/ videos / upload',function(request,response){
     console.log('已收到请求')
}
</ code> </ pre>

但是,当调用.post()时,它似乎没有执行。 该请求在Firebug的Net记录器中无处可见,并且node.js控制台也不记录任何内容。</ p>

当我直接在Firebug控制台中键入请求时,它执行得很好。</ p>

使用$ .ajax()也不起作用。</ p>

谢谢。</ p>
     </ div>

展开原文

原文

I have the following AJAX call through jQuery:

// var upload = some JSON data
$.post('/videos/upload', upload);

And this express.js API part to handle the request:

app.post('/videos/upload', function(request, response) {
    console.log('Request received')
}

However, when .post() is called, it does not seem to be executing. The request is nowhere to be seen in Firebug's Net logger, and the node.js console doesn't log anything, either.

When I type the request directly into the Firebug console, it executes just fine.

Using $.ajax() does not work, either.

Thanks in advance.

1个回答


要排除故障并隔离问题</ strong>,您需要确定这是后端问题还是前端问题。</ p>

后端检查</ h2>

尝试使用类似邮递员< / a>,直接使用应发布的数据访问端点。 如果您从未执行过该 console.log </ code>,那么您的路由可能会遇到一些问题。</ p>

前端检查</ h2>

如果可行,请在Chrome中查看“开发工具”的“网络”标签,并确保该请求与您在Postman中所做的请求相同。</ p>
     </ div>

展开原文

原文

To troubleshoot and isolate the problem, you need to determine if this is a backend or a frontend problem.

Backend Check

Try using something like Postman to hit the endpoint directly with the data that should be posted. If you never get that console.log to execute then you may have some problems with your routes.

Frontend Check

If that works, then look at the Network tab of your Dev Tools in Chrome and make sure that the request looks the same as the one you make in Postman.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问