【问题标题】:Send data to restful service将数据发送到 RESTful 服务
【发布时间】:2014-07-11 08:28:22
【问题描述】:

我正在尝试将数据作为 json 字符串发送到 restful 服务。因为这是一个跨域调用,我使用 jsonp 来执行此操作。

var arr={"isExceptionLogged":"0","allocInstructionId":"000001879HVWC1","allocInstructionIdtmp":"000001879HVWC}
               $.support.cors = true;
               $.ajax( {
                     headers: {
                         'Accept': 'application/json',
                     },
                     crossDomain: true,
                     url: "http://<url>",
                     type: "POST",
                     data: JSON.stringify( arr ),
                     dataType: "jsonp",

                     success: function ( result )
                     {
                         alert("successful");
                       },
                     error: function ( xhr, ajaxOptions, thrownError )
                     {
                         alert( "Error" );
                         alert( xhr.status );
                         alert( thrownError );
                     }
                 } );

但是我得到错误 200 ,jquery= 12345 没有被调用。

我的服务代码是:

@Path("/update")
@POST
@Consumes({ MediaType.APPLICATION_JSON})
public void updatefunctions(bean abc){

    abc.toString();
}

【问题讨论】:

  • 在他们的论坛发布这个问题,他们会帮你解决的。。

标签: jquery json rest jsonp


【解决方案1】:

您没有关闭数组 var 中“allocInstructionIdtmp”值的字符串。应该是:

var arr={"isExceptionLogged":"0","allocInstructionId":"000001879HVWC1","allocInstructionIdtmp":"000001879HVWC**"**}**;**

【讨论】:

  • 我在代码中关闭它。它是一个巨大的字符串,所以我将其修剪并张贴在这里
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 2013-09-26
  • 2014-03-23
  • 1970-01-01
  • 1970-01-01
  • 2015-03-08
相关资源
最近更新 更多