我想调用跨域上的API。这是我做的:
$(document).ready(function() {
var pm_url = 'http://localhost:8080/alfresco/service/api/login';
pm_url += '?u=${args.user}&pw=${args.pass}&format=json';
$.ajax({
url: pm_url,
dataType: 'jsonp',
jsonp: 'callback',
jsonpCallback: 'redirect'
});
});
var redirect=function(data) {
var token= JSON.parse(data);
alert(token.data.ticket);
var entity="";
var id="";
var rows="";
var sortColumn="";
var sortType="";
var sAuthor="";
var permission="";
var branch="";
var category="";
var subCategory="";
var jurisdiction="";
var baseDocket="";
<#if (args.entity) ??>
entity= "${args.entity}";
</#if>
<#if (args.id) ??>
id= "${args.id}";
</#if>
<#if (args.rows) ??>
rows= "${args.rows}";
</#if>
<#if (args.sortColumn) ??>
sortColumn= "${args.sortColumn}";
</#if>
<#if (args.sortType) ??>
sortType= "${args.sortType}";
</#if>
<#if (args.sAuthor) ??>
sAuthor= "${args.sAuthor}";
</#if>
<#if (args.permission) ??>
permission= "${args.permission}";
</#if>
<#if (args.branch) ??>
branch= "${args.branch}";
</#if>
<#if (args.category) ??>
category= "${args.category}";
</#if>
<#if (args.subCategory) ??>
subCategory= "${args.subCategory}";
</#if>
<#if (args.jurisdiction) ??>
jurisdiction= "${args.jurisdiction}";
</#if>
<#if (args.baseDocket) ??>
entity= "${args.baseDocket}";
</#if>
var url="http://localhost:8080/alfresco/s/documentManagement?entity="+entity+"&id="+id+"&rows="+rows+"&sortColumn="+sortColumn+"&sortType="+sortType+"&sAuthor="+sAuthor+"&permission="+permission+"&branch="+branch+"&category="+category+"&subCategory="+subCategory+"&jurisdiction="+jurisdiction+"&baseDocket="+baseDocket+"&alf_ticket="+token.data.ticket;
window.location.replace(url);
};
但我得到了这个: 登录?u = admin&amp; pw = admin&amp; format = json&amp; callback = redirect&amp; _ = 1471932310898:2 Uncaught SyntaxError:意外的令牌:
我哪里出错了?请纠正我。