开发者

Extjs to call a RESTful webservice

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);
   }
});

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

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');
  }
});

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 w开发者_高级运维orks fine and i get the response as expected.

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


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).

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


The problem is exactly because of the reason ob1 and Chuck Hinson described.

I have an RESTful service, wich is running on Tomcat.

And i made a static client(no deployed to Tomcat) using ExtJs with Json reader. I just made an html page with ExtJs integrated consuming REST service like url: http://localhost:8080/service/invoices/

And all the time ExtJs was making OPTIONS request, not GET or POST even if i was setting them as being used methods. The problem is this security feature, because Client is not the part of same application and i am doing AJAX call between domains.

As soon as i put my client to my Web application and deployed to Tomcat and started using relative calls it started working.


if you don't want cross-domain request, please remove the website prefix 'http://website' from propery url of ajax proxy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜