Node express 4 post提交报错

Error missing content-type header status 415

//ajax提交

    $.ajax({
        url:'/pics',
        type: 'POST',
        data:'{"upload":true}',
        dataType:'json',
        success:function(data){
            alert('success');
        },
        error:function(err){
            alert(123);
        }
    })
    
    调用路由下的js router.post('/pics',function(){
         ....    
         
         res.json({//json串});    
    })
    
    执行后就一直提醒
    unsupported content-Type  status 415
    
    
阅读 3.9k
3 个回答

你添加一下content-type?
这句话是提示你找不到content-type

response.writeHead(200, { 'Content-Type': 'text/plain' });
新手上路,请多包涵

上代码看看,这个错我也见过,忘记代码什么样了

最后发现把
$.ajax
换成
XMLHttpRequest()的形式就可以了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题