SAPUI5 JSONModel 和 JSONP [英] SAPUI5 JSONModel and JSONP

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

问题描述

我有一个基于 JSONP 的 REST 服务,我需要将它加载到 JSONModel 中.

网址:http://pipes.yahoo.com/pipes/pipe.run?_id=eb8dcd1d84e4aa323378ce219683878a&_render=json&_callback=bbcModelLoaded(_callback 参数是要调用的 JSONP 函数)

从这里创建 JSONModel 的首选方法是什么?

我宁愿避免自己处理 AJAX 调用.

如果您使用 JSONP url 创建 JSONModel 的错误是:

<块引用>

出现以下问题:parsererror - bbcModelLoaded({"count":52,...

解决方案

不需要 $.getJSON、JSONP 模型或任何其他代码采用.

这实际上是开箱即用的:

new sap.ui.model.json.JSONModel("http://pipes.yahoo.com/pipes/pipe.run?_id=eb8dcd1d84e4aa323378ce219683878a&_render=json&_callback=?");

这里的实例:http://jsbin.com/babiqoze/1/edit?html,输出

重要的是您将回调参数的值设置为?"以便 jQuery 检测到它并将其作为 JSONP 请求处理.http://api.jquery.com/jquery.getjson/#jsonp>

I have a JSONP-based REST service which I need to load into a JSONModel.

URL: http://pipes.yahoo.com/pipes/pipe.run?_id=eb8dcd1d84e4aa323378ce219683878a&_render=json&_callback=bbcModelLoaded (_callback parameter is the JSONP function to be called)

What is the preferred way of creating a JSONModel from this?

I would prefer to avoid handling the AJAX call myself.

Error if you create a JSONModel with a JSONP url is:

The following problem occurred: parsererror - bbcModelLoaded({"count":52,...

解决方案

There is no need for $.getJSON, a JSONP model or any other code adoption.

This actually works out of the box:

new sap.ui.model.json.JSONModel("http://pipes.yahoo.com/pipes/pipe.run?_id=eb8dcd1d84e4aa323378ce219683878a&_render=json&_callback=?");

Live example here: http://jsbin.com/babiqoze/1/edit?html,output

The important thing is that you set the value of the callback parameter to "?" so that jQuery detects it and handles it as an JSONP request. http://api.jquery.com/jquery.getjson/#jsonp

这篇关于SAPUI5 JSONModel 和 JSONP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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