这次还是prototype.js 和 jQuery.js冲突的问题,前面说到过解决办法,以及上网说的大部分方法都只能解决$的冲突问题。我先引入了prototype.js 再引入jQuery.js,在用了jquery中的$,然后来用prototype中的ajax的时候,ajax的方法就不启作用了。 最后改为了用 jQuery.js中 ajax 。现在记录下两者ajax调用的区分:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>Insert title here
当然,在使用jQuery时,可以使用如下方式给组件注册相关事件。需要注意prototype和jQuery对$符的冲突。
$(document).ready(function(){ $("#callJQueryAjax").click(function(){ jQuery.ajax({ type:"post", url:"test1.jQuery?para1=value1", dataType:"text", success:function(data){ alert("value returned from sever is : " + data ); } }); }); };
上述Ajax申请资源为普通servlet,web.xml简要配置如下,亦可在servlet3.0下使用注解方式。
test1 com.test.Test1OfPrototype test1 /test1.prototype test1JQuery com.test.Test1OfJQuery test1JQuery /test1.jQuery