调用跨域ajax调用时出错 [英] Error in calling cross domain ajax call

查看:98
本文介绍了调用跨域ajax调用时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在跨域RestFul Ws调用frm jquery ajax方法...

但是ajax调用没有正确返回结果....

我使用嵌入式码头服务器和球衣来构建RestFul WS ...



ws url是localhost:8888 / admin / Session ...

Web服务公开代码如下...



Hi All,
I am making cross domain RestFul Ws call frm jquery ajax method...
But the ajax call is not returning results properly....
I have used a embedded jetty server and jersey to build the RestFul WS...

The ws url is localhost:8888/admin/Session...
The web service exposed code is as below...

@GET
@Produces(MediaType.TEXT_XML)
public String getAllSession(){
	List<session> sessions = dao.getAllSession(); 
	return XMLToJava.fromJavaToXML(sessions.toArray(new Session[sessions.size()]));
}



网络服务返回以下结果...


The web Service return the following result...

<session-array>
<session>
<id>1</id>
<serverhost>*.*.*.*</serverhost>
<servername>praneethr</servername>
<port>8008</port>
<starttime>1397130980858</starttime>
<endtime>0</endtime>
<session>Session_10042014172616</session>
<terminated>false</terminated>
<status>Running</status>
</session>
</session-array>



ajax代码是


The ajax code is

$(".menuItem").click(function() {
    var adminURL = "http://localhost:8888/admin";
    var id = adminURL + "/" + $(this).attr("id");
    alert(id);
    $.ajax({
    	cache: false,
    	type : "GET",
    	url : id,
    	crossDomain: true,
    	headers: { 'Access-Control-Allow-Origin': '*' },
    	contentType: 'application/xml; charset=utf-8',
    	dataType: "xml",
    	success : function(xml) {
    		alert("Callback done!");
    		transformXsl(data, id + "XSL.xsl");
    	},
    	error : function(xhr) {
    		alert(xhr.responseText);
    		alert(xhr.statusText);
    		alert(xhr.status);
    	}
    });
});





这是返回错误...

它返回一个未定义的404错误...



通过firebug Net面板检查时显示以下错误...

但是xml语法仍然正确...



This is returning error...
It returns a undefined 404 error...

When inspected through firebug Net panel it is showing the following error...
But the xml syntax is still correct...

XML Parsing Error: syntax error Location: moz-nullprincipal:{6ab5d49e-5e9c-44f4-b391-9807503cf157} Line Number 1, Column 1:

Reload the page to get source for: http://localhost:8888/admin/Session?_=1398053...



任何帮助表示赞赏...

全部谢谢....





已添加 pre 标记。

[/编辑]

推荐答案

.menuItem)。click( function (){
var adminURL = http:// localhost:8888 / admin;
var id = adminURL + / +
(".menuItem").click(function() { var adminURL = "http://localhost:8888/admin"; var id = adminURL + "/" +


this )。attr( id);
alert(id);
(this).attr("id"); alert(id);


.ajax({
cache: false
类型: 获取
url:id,
crossDomain: true
header:{' Access-Control- Allow-Origin'' *'},
contentType:' application / xml; charset = utf-8'
dataType: xml
成功: function (xml) {
alert( 回调完成!);
transformXsl(data, id + XSL.xsl);
},
错误: function (xhr){
alert(xhr.responseText);
alert(xhr.statusText);
alert(xhr.status);
}
});
});
.ajax({ cache: false, type : "GET", url : id, crossDomain: true, headers: { 'Access-Control-Allow-Origin': '*' }, contentType: 'application/xml; charset=utf-8', dataType: "xml", success : function(xml) { alert("Callback done!"); transformXsl(data, id + "XSL.xsl"); }, error : function(xhr) { alert(xhr.responseText); alert(xhr.statusText); alert(xhr.status); } }); });





这是返回错误...

它返回一个未定义的404错误...



通过firebug Net面板检查时显示以下错误...

但是xml语法仍然正确...



This is returning error...
It returns a undefined 404 error...

When inspected through firebug Net panel it is showing the following error...
But the xml syntax is still correct...

XML Parsing Error: syntax error Location: moz-nullprincipal:{6ab5d49e-5e9c-44f4-b391-9807503cf157} Line Number 1, Column 1:

Reload the page to get source for: http://localhost:8888/admin/Session?_=1398053...



任何帮助表示赞赏...

全部谢谢....





已添加 pre 标记。

[/编辑]


这篇关于调用跨域ajax调用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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