jquery ajax方法url请求action没有返回json数据。

2019-03-25 13:50|来源: 网路

具体代码如下:
jquery代码
$(function(){
	$("#submButton").click(function(){
		alert("點擊了");
		getNpcsByMapId(1);
	});
})
function getNpcsByMapId(mapId) {
	var jsonObjs;
	alert("调用了");
	$.ajax({dataType : 'json',url : 'findNpcsByMapId&map.mapId='+mapId,success : function(data){
		alert("完成了");
		jsonObjs = data;
	}});
//	var npcs = new Array();
//	for(var j = 0; j < jsonObjs.length; j++) {
//		npcs.push(jsonObjs[j].id,jsonObjs[j].name,
//			jsonObjs[j].pos1x,jsonObjs[j].pos1y,jsonObjs[j].pos1z,
//			jsonObjs[j].pos2x,jsonObjs[j].pos2y,jsonObjs[j].pos2z,
//			jsonObjs[j].pos3x,jsonObjs[j].pos3y,jsonObjs[j].pos3z,
//			jsonObjs[j].pos4x,jsonObjs[j].pos4y,jsonObjs[j].pos4z,
//			jsonObjs[j].pos5x,jsonObjs[j].pos5y,jsonObjs[j].pos5z,
//			jsonObjs[j].template.id);
//	}
//	document.getElementById("aa").innerHTML=npcs[1];
	//callExternalInterface(npcs);
}


jsp页面代码
<body>
	<form id="iii">
		<input type="text" name="map.mapId"/>
		<input id="submButton" type="button" value="提交"></input>
	</form>
	<textarea rows="" cols="" id="aa" style="width: 800px;height: 600px"></textarea>
  </body>


action代码
@Action(results = { @Result(type = "json", params = { "excludeProperties", "maps,templates" }) }, value = "findNpcsByMapId")
	public String findNpcsByMapId() throws UnsupportedEncodingException {
		npcs = creatureService.getAllNpcByMap(map);
		return "success";
	}


直接在地址栏输入http://localhost:8080/xxx/findNpcsByMapId?map.mapId=1 能得到json数据在网页上打开,但是在jsp中点击提交按钮却只能执行到“调用了”这一步,然后就没有返回了。

请教一下其中的问题。

问题补充:
timeroading 写道
alert 一下data看看有没有数据返回

没有数据返回,我认为是$.ajax没有执行成功但是又不知道错在哪里。

问题补充:把url直接写成'findNpcsByMapId&map.mapId=1’ 还是一样的问题。

问题补充:
timeroading 写道
'findNpcsByMapId&map.mapId='+mapId
你的url 有问题吧
'findNpcsByMapId?map.mapId='+mapId

确实,这里写错了。感谢!

相关问答

更多