我正在使用回调函数,因为我希望将数据填充到另一个域上(通过使用我的javascript)。AJAX成功后的Callaback函数
/*
*
* Description: This function is AJAX loader for Footer and processing Callback function as a response"
*
* @Param :actionName : The URL to be called
*
* */
function ajaxFooterLoader(actionName) {
$.ajax({
type: 'GET',
url: "http://localhost:8080/ajax/ttsGetContent.do?languageCode=en&productType=package&pageId=packageSearchResults&format=jsonp&includes=FOOTER",
dataType: "json",
success: function(response) {
//WHAT SHOULD I DO???
},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
}
下划线,是我通过AJAX我的网址调用后得到响应,我传递格式的URL是直接返回了我要调用的函数,即processFooter。
不过,我不明白我应该成功之后做的,所以它直接调用我的函数,它是通过回拨电话从服务器
processFooter({
"copyRight": {
"description": null,
"id": null,
"name": "© 2015 AC",
"style": null
}
})
我的功能
URL响应返回: 这是AJAX返回的功能,定义如上AJAX调用
/*
*
* Description: This function will process footer
*
* @Param :dataFooter : it takes JSON as input
*
*
* */
function processFooter(dataFooter) {
mergeTemplateFooter(dataFooter);
}
请指教我的ajax成功应该如何调用此函数?
在此先感谢
你的服务器似乎返回JSONP,JSON不是。为什么? –
是的,它的回调JSONP回调 – user2985842
即使我用jsonp试过,问题是我的函数在成功后会被执行吗? – user2985842