Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONP - return HTML

Tags:

jquery

jsonp

I'm using JSONP with code:

<script>
$.ajax({
    url:"http://localhost:8080/pool/main/?pool=abcd",
    dataType: 'JSONP',
    success:function(response){
        $('#pool').append(response);
    },
    error:function(){
        alert("ERROR");
        },
});
</script>

I have to user JSONP, becouse i need ajax cross domain

In my application response from "http://localhost:8080/pool/main/?pool=abcd" is HTML code.

I wanted to display this code in my page, but there is an error, because as i assume, i can't return html.

ERROR - i mean - it produce me this code error:function(){ alert("ERROR"); }, but i see in firebug that the response from my page http://localhost:8080/pool/main/?pool=abcd is ok. But secoundly. i don't know how to put the response to html element.

My question is - CAN I or I CAN'T.

If i can - how to do this ?

like image 774
Ilkar Avatar asked Nov 05 '22 08:11

Ilkar


1 Answers

If you want to use JSONP, you need to generate a piece of scripts calling a method with returned data. If you want to get a piece of HTML, your url should output code like this:

callFunction("<div>abc</div>");
like image 145
Jeffrey Zhao Avatar answered Nov 09 '22 11:11

Jeffrey Zhao