ExtJS的调用RESTful Web服务 [英] Extjs to call a RESTful webservice

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

问题描述

我试图做一个RESTful Web服务调用使用ExtJS的。下面是code我使用:

I am trying to make a RESTful webservice call using Extjs. Below is the code i am using:

Ext.Ajax.request({ url: incomingURL ,
   method: 'POST',
   params: {param1:p1, param2:p2},
   success: function(responseObject){
     var obj = Ext.decode(responseObject.responseText);
     alert(obj);
   },
   failure: function(responseObject){
     var obj = Ext.decode(responseObject.responseText);
     alert(obj);
   }
});

,但它不工作,请求使用OPTIONS方法而不是POST发送。

but it does not work, the request is sent using OPTIONS method instead of POST.

我也尝试使用下面code做同样的事情,但结果是一样的:

I also tried to do the same thing using below code but result is the same:

var conn = new Ext.data.Connection();
conn.request({
  url: incomingURL,
  method: 'POST',
  params: {param1:p1, param2:p2},
  success: function(responseObject) 
  {
    Ext.Msg.alert('Status', 'success');
  },
  failure: function(responseObject) 
  {
    Ext.Msg.alert('Status', 'Failure');
  }
});

但是,当我尝试使用基本Ajax调用做同样的事情(使用浏览器直接对象就是XMLHtt prequest()或的ActiveXObject(Microsoft.XMLHTTP)),它工作正常,我也得到了响应预期

But when i tried to do the same thing using basic ajax call ( using the browser objects directly i.e. XMLHttpRequest() or ActiveXObject("Microsoft.XMLHTTP")) it works fine and i get the response as expected.

任何人都可以请帮助我,因为我不能够理解我在做什么毛病ExtJS的Ajax调用?

Can anyone please help me, as i am not able to understand what i am doing wrong with extjs ajax call?

推荐答案

您不能让域之间的一个标准的AJAX调用。该网址Ext.Ajax.request应该是一个相对的(相对于剧本的由来)。

You can't make a standard AJAX call between domains. The URL for Ext.Ajax.request should be a relative one (relative to the script's origin).

如果你想要做跨域调用,使用ScriptTagProxy或者这样的。

If you want to do cross-domain calls, use a ScriptTagProxy or such.

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

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