今天开发竞拍式语文读写游戏的过程中,使用Ajax传递用户操作记录,但Action只能接收到用户ID,用户竞拍出价price和关键词word都为Null。
采用原生的Ajax写法:
var xhr = createXmlHttp();
xhr.open("GET", "${pageContext.request.contextPath}/bid_bidding.action?playerID=" + gameState.curPlayer + "&price=" + gameState.curBid + "&word=" + gameState.curKeyword, true);
xhr.send(null);
一度怀疑自己Ajax的url写错,尝试了网上的很多方法,set(),get()方法没问题,参数名也正确,但还是接收不到参数。
也尝试了JQuery的Ajax,结果还是一样。
无意间修改了参数名称:
xhr.open("GET", "${pageContext.request.contextPath}/bid_bidding.action?curPlayer=" + gameState.curPlayer + "&curBid=" + gameState.curBid + "&curKeyword=" + gameState.curKeyword, true);
然后就参数就传递成功了。
思考之后猜测出问题的原因,price和word是原型Bid里的两个属性,是否因为url传递的参数和属性名重复了,所以导致参数传递失败?