【发布时间】:2015-06-20 17:19:35
【问题描述】:
我正在使用回调,因为我希望将我的数据填充到另一个域(通过使用我的 javascript)。
/*
*
* 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 后得到的响应,我在 url 中传递格式,它直接返回我要调用的函数,即 processFooter。
但是,我不明白成功后我应该怎么做,所以它直接调用我的回调调用返回的函数
来自服务器的 URL 响应
processFooter({
"copyRight": {
"description": null,
"id": null,
"name": "© 2015 AC",
"style": null
}
})
我的功能: 这是AJAX返回的函数,上面定义了AJAX调用
/*
*
* Description: This function will process footer
*
* @Param :dataFooter : it takes JSON as input
*
*
* */
function processFooter(dataFooter) {
mergeTemplateFooter(dataFooter);
}
请告诉我我的 ajax 成功应该如何调用这个函数?
提前致谢
【问题讨论】:
-
您的服务器似乎返回 JSONP,而不是 JSON。为什么?
-
是的,它返回 JSONP 用于回调
-
即使我尝试使用 jsonp ,问题是成功后我的函数将如何执行?
标签: javascript jquery