weixin_33675507 2015-04-10 21:06 采纳率: 0%
浏览 21

jQuery Post提供休息服务

I´m trying to access a REST service using the post method but I get this response.

XMLHttpRequest cannot load http://192.168.0.13:8090/PruebaRestEjemplo/api/entidades.usuarios. Request header field Content-Type is not allowed by Access-Control-Allow-Headers.

But the content type header is allowed, I can try my services with postman and I get no error. What can it be? this is my code.

     var prueba = new Object();
     prueba.nombreUsuario = "Miguel";
     prueba.apellidoUsuario = "De Cervantes";
     prueba.usuarioLogin = "MCervantes";
     prueba.contrasenaLogin = "Mcervantes";

     $.ajax
      ({
        type: "POST",
        url: url,
        contentType:"application/json; charset=UTF8",
        dataType:"json",
        data: prueba,
        async: false,
        beforeSend: function (xhr){ 
            xhr.setRequestHeader('Authorization', x.basicAuth(x.usuario, x.clave));
        },
        success: function(result){
            callback(result);
        }
    });
  • 写回答

1条回答 默认 最新

  • 笑故挽风 2015-04-10 21:29
    关注

    Rest Web services always take the data in json or XML format and while posting the data to a web service you need to serialize the javascript object into JSON or XML object as specified in web service. In your code the prueba is the javaScript object and you need to serialize the object to make it JSON or XML which ever is supported by your web service. You can use this function just before the Ajax call.
    JSON.stringify(prueba);

    Hope it helps.

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题