Show jquery jsonp callback result

一曲冷凌霜 提交于 2019-12-12 03:49:48

问题


Sorry as my question stupid and elementary....

how write jsonp callback result to page, I'm trying such with jquery but result - Data Saved: [object Object]

function alertResponse(text) {
document.write( "Data Saved: " + text );
}


$.ajax({
    url: URL,
    dataType: 'jsonp',
    jsonpCallback: 'alertResponse'
});

the rusult by url is

jsonp1293628807768({"text":"  <div class=\"package_search_result_table\" 710px>\r\n    <div class=\"itt_title\" style=\"width: 710px;\">\r\n

回答1:


You can use JSON library and it's JSON.stringify function to display the text.




回答2:


jsonpCallback is a way to know the name of the function that will handle the callback. It's not supposed to be the callback function! You ought to try complete: alertResponse




回答3:


If you want jQuery to call a specific function you must add jsonp: false. Writing only jsonpCallback is useless

$.ajax({
    url: URL,
    dataType: 'jsonp',
    jsonp: false,
    jsonpCallback: 'alertResponse'
});


来源:https://stackoverflow.com/questions/4555624/show-jquery-jsonp-callback-result

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!