使用JQuery Ajax和JSONP调用的OData服务 [英] Call OData Service using JQuery Ajax and JSONP

查看:769
本文介绍了使用JQuery Ajax和JSONP调用的OData服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JQuery $就运行了一些问题调用OData服务。


当我打电话用的dataType服务:JSONP,我得到的200状态code和我需要的数据,但是它落入我的JQuery的错误:功能(数据)


当我打电话用的dataType服务:JSON,我什么也没得到,调用该服务甚至不发生


这是我的电话阿贾克斯:

    
    $阿贾克斯({
        beforeSend:功能(要求){
            request.setRequestHeader(接受,应用/ JSON的;字符集= UTF-8);
        },
        键入:GET,
        网址:this.uri +过滤器,
        数据类型:JSONP
        成功:功能(数据){
            //我从来没有在这里,但在提琴手我得到一个200状态code
        },
        错误:功能(数据){
            //这工作,给我的数据,但它在JQuery的错误处理程序
            // $ .parseJSON(data.responseText)
        }
    });
    



我试过几个变化JSONP:假,回调等,并没有成功。我还要提到的是网站和ODATA的WebAPI在同一台服务器上,但该网站是通过HTTPS访问,然后在客户端AJAX通过HTTP调用服务。

I'm trying to call an OData service using JQuery $.ajax and running into some issues.

When I call the service with dataType: "jsonp", I get a status code of 200 and the data I need but it falls into my JQuery error: function(data)

When I call the service with dataType: "json", I get nothing, the call to the service does not even happen.

Here is my .ajax call:
$.ajax({ beforeSend: function(request) { request.setRequestHeader("Accept", "application/json;charset=utf-8"); }, type: "GET", url: this.uri + filter, dataType: "jsonp", success: function(data) { // I never get here but in fiddler I get a 200 status code }, error: function(data) { // This works and gives me the data but it's in the JQuery error handler // $.parseJSON(data.responseText) } });
I've tried several variations "jsonp: false", "callback", etc and without success. I should also mention that the website and odata webapi are on the same server but the website is accessed via https and then the client ajax calls the service via http.

会有人能告诉我,我要去哪里错了?

Would anyone be able to tell me where I'm going wrong?

在此先感谢!

推荐答案

的努力我终于得到它通过跳过jQuery和使用xmlhtt prequest对象工作无数个小时后,这是我的工作code:




    VAR URI = this.uri +过滤;

After countless hours of effort I finally got it to work by skipping JQuery and using xmlhttprequest object, here's my working code:

var uri = this.uri + filter;

var http_request = new XMLHttpRequest();
http_request.setRequestHeader("Authorization", "Negotiate");

http_request.onreadystatechange  = function() {
    if (http_request.readyState == 4  ) {
        var data = JSON.parse(http_request.responseText);
        alert(data.value[0].Name);
    }
}

http_request.open("GET", uri, true);
http_request.send();    

我借了来自世界各地的作品在网络上,以便其他人应有的荣誉。


I borrowed pieces from everywhere on the web so others deserve the credit.

这是本地Intranet上运行,使用IE浏览器而已,如果任何人有另一种意见认为我可以尝试或做的更好的办法,我会AP preciate您的反馈意见。


谢谢!

This is for use on a local intranet running IE only, if anyone has another suggestion I can try or a better way of doing this I would appreciate your feedback.

Thanks!

这篇关于使用JQuery Ajax和JSONP调用的OData服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆