AJAX JSONP:解析响应会导致错误

时间:2016-05-22 14:37:08

标签: jquery ajax wcf jsonp

每当我调用我的服务时,我都会得到解析错误:

SyntaxError: missing ; before statement
{"Catagory":"Sample language","Name":"Sample Book","Price":50}
-----------↑

以下是我的客户端代码:

<script>
  $(document).ready(function() {
    $('#btSubmit').click(function () {
      $.ajax({ 
        type:"GET",
        url: url, // Location of the service
        contentType: "application/json;charset-uf8", // content type sent to server
        dataType: "jsonp", //Expected data format from server
        success: function (msg) {
          alert(msg);
          //Implement get data from service as you wish
        },
        error: function (err) {
          alert(err);
          // When Service call fails
        }
      });     
    });
  });
</script>

服务器端代码..我正在使用wcf服务

[ServiceContract(Namespace = "JsonpAjaxService")]
public interface IBooks
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat =            WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json)]      
BookDetails ShowBookDetails(string sBookID);

[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "json/{id}")]
BookDetails JsonData(string Id);
}

0 个答案:

没有答案