如何使用 phonegap/jQueryMobile 从 OpenCart 获取 JSON 格式的产品 [英] How to get products in JSON format from OpenCart using phonegap/jQueryMobile

查看:15
本文介绍了如何使用 phonegap/jQueryMobile 从 OpenCart 获取 JSON 格式的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,是否可以从我的 OpenCart 商店,使用 Ajax、JavaScript/jQuery 的 phonegap 移动应用程序获取 JSON 格式的产品目录.OpenCart 允许这样的事情吗?

Is there anyway, to fetch product catalog in JSON format from my OpenCart store, from a phonegap mobile application using Ajax, JavaScript/jQuery. Does OpenCart allow for such a thing?

欢迎任何想法或代码:)

Any ideas or code are welcome :)

推荐答案

OcJoy 是正确的,但提供的解决方案将包含我认为不是您想要的输出的所有页面数据.

OcJoy is going right way but the solution provided will contain all the page data which I guess is not Your desired output.

代替他的解决方案,你应该在 $this->response->setOutput($this->render());:

Instead of his solution, You should do something like this (assuming You need only the products JSON array) before $this->response->setOutput($this->render());:

if(isset($this->request->get['json'])) {
    echo json_encode($this->data['products']);
    die;
} else

然后在点击 http://www.example.com/index.php?route=product/category&path=20&json 之后,只有 ID 为 20 的类别的 products 数组的 JSON 会输出.

Then after hitting http://www.example.com/index.php?route=product/category&path=20&json only the JSON of products array of category with ID 20 will be output.

从模板中调用它作为 AJAX 请求,你可以这样做:

to call this from within a template as an AJAX request, You could do:

$(document).ready(function(){
    $.ajax({
        url: 'index.php?route=product/category&path=<CATEGORY_ID>&json',
        type: 'get',
        dataType: 'json',
        beforeSend: function() {
        },
        complete: function() {
        },
        success: function(data) {
            if (data.length > 0) {
                // do something here with the products in data array
            }
        }
    });
});

确保将 替换为上面 URL 中的正确值,并在 success 回调函数中添加所需的功能.

Make sure to replace <CATEGORY_ID> with the right value in the URL above and to add the desired functionality within the success callback function.

这篇关于如何使用 phonegap/jQueryMobile 从 OpenCart 获取 JSON 格式的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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