本文介绍了如何在sencha touch2中使用外部webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 sencha touch2 的新手,我想在 sencha touch2 中使用外部 Web 服务.我为此原因编写了代码,显示警报 msg 不起作用!在控制台给出这样的错误 XMLHttpRequest 无法加载 http://localhost/SLS.BRND.Services/Service1.asmx/Helloworld?_dc=1336466078991&method=Helloworld&format=json.

I am new to sencha touch2 and i want to consume external web service in sencha touch2.I have written code for this cause, showing alert msg not working! in console giving error like this XMLHttpRequest cannot load http://localhost/SLS.BRND.Services/Service1.asmx/Helloworld?_dc=1336466078991&method=Helloworld&format=json.

Origin http://localhost:49692 不被允许访问控制允许来源.app/view/Blog.js?_dc=1336466047687:27响应状态:- 0

请帮我看看有什么问题.谢谢

please help me what is the problem. Thank you

这是我的代码:-

   Ext.define("GS.view.Blog", {
    extend: 'Ext.navigation.View',
    xtype: 'blog',
    config: {
        title: 'WebService',
        scrollable: true,       
        items: [
            {
            xtype: 'button',
            text: 'Press Me',
            height: 40,
            width: 200,
            listeners: {
                tap: function () {
//                    alert("Hi Welcome To Sencha");
                    Ext.Ajax.request({
                        method: 'GET',
                        url: 'http://localhost/SLS.BRND.Services/Service1.asmx/Helloworld',
                        params: { method: 'Helloworld', format: 'json' },
                        success: function (response, request) {
                            alert('Working!')
                            alert(response.responseText)
                            console.log('Response:-' + response.responseText)
                        },
                        failure: function (response, request) {
                            alert('Not working!')
                            console.log('Response Status:- ' + response.status)
                        }
                   });
                }
            }
          }
        ]
    }
});

推荐答案

试试这个代码

        Ext.data.JsonP.request({

                    url: 'http://localhost/SLS.BRND.Services/Service1.asmx/Helloworld',
                    params: { method: 'Helloworld', format: 'json' },
                    success: function (response) {
                        alert('Working!')
                        console.log(response);
                    },
                    failure: function (response) {
                        alert('Not working!')
                        console.log(response);
                    }
               });

这篇关于如何在sencha touch2中使用外部webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 22:15