.js文件中寫ajax請求

 $.ajax({ 
             url:'${contextPath}/shopManage/getShopInfo', 
             type:'post',
             dataType:'json',

            success:function(data){}javascript

});java

一般ajax請求都是這樣寫的,可是一旦寫大.js文件中,"${contextPath}"就會解析不出,解決的辦法是:ajax

1.在.jsp頁面中,添加:<script type="text/javascript">var ctx="${contextPath}";<script >json

2.在.js文件中jsp

$.ajax({ 
             url:'ctx/shopManage/getShopInfo', 
             type:'post',
             dataType:'json',
post

            success:function(data){}url

});ip