ajax加载script不能返回变量值,需刷新
jsp页面:
var templateFrozenColumns = [[]];
var templateColumns = [[]];
$.ajax({
async: false,
url: '/portalIntegration/js/i_month.js',
dataType: 'script',
success: function(data) {
templateFrozenColumns = frozenColumns;
templateColumns = columns;
}});
i_month.js脚本:
var frozenColumns = [[
{title:'',field:'vaMark',align:'center',width:40},
{title:'月',field:'vaItemName',align:'center',width:120,sortable:true}
]];
var columns = [[
{title:'标题1',colspan:3},
{title:'标题2',colspan:3},
{title:'标题3',colspan:3}
]];
页面返回为空,我用firebug调试没有错误,但没有success进去,响应的是下面html文件,貌似是把所有js文件列出来:
<html>
<head>
<title>Directory Listing For /portalIntegration/js/</title>
<STYLE><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></STYLE> </head>
<body><h1>Directory Listing For /portalIntegration/js/ - <a href="/fjdc/portalIntegration/"><b>Up To/portalIntegration</b></a></h1><HR size="1" noshade="noshade"><table width="100%" cellspacing="0" cellpadding="5" align="center">
<tr>
<td align="left"><font size="+1"><strong>Filename</strong></font></td>
<td align="center"><font size="+1"><strong>Size</strong></font></td>
<td align="right"><font size="+1"><strong>Last Modified</strong></font></td>
</tr><tr>
<td align="left">
<a href="/fjdc/portalIntegration/js/de_sale_pricearea.js"><tt>de_sale_pricearea.js</tt></a></td>
<td align="right"><tt>1.0 kb</tt></td>
<td align="right"><tt>Wed, 12 Feb 2014 02:07:33 GMT</tt></td>
</tr>
我再刷新一次页面就正常了,ajax才success进去,响应返回的是
var frozenColumns = [[
{title:'',field:'vaMark',align:'center',width:40},
{title:'月',field:'vaItemName',align:'center',width:120,sortable:true}
]];