JSONP - HTML Return

I am 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 need a JSONP user because I need ajax cross domain

My application response from " http://localhost:8080/pool/main/?pool=abcd " contains HTML code.

I wanted to display this code on my page, but there is an error because, as I assume, I cannot return html.

ERROR - I mean - this gives me this error:function(){ alert("ERROR"); } code error:function(){ alert("ERROR"); } error:function(){ alert("ERROR"); } , but I see in firebug that the response from my page http://localhost:8080/pool/main/?pool=abcd is fine. But sketchy. I do not know how to put the response to the html element.

My question is - CAN I NOT.

If I can - how to do it?

+4
source share
3 answers

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

 callFunction("<div>abc</div>"); 
+1
source

You can display the HTML response text on your page. You just need to add the response value to any HTML element, such as <div> or <span> .

You can also do this with the following code.

 var URL = "http://localhost:8080/pool/main/?pool=abcd"; new Request({ method: 'POST', url: URL, assign: 'true', onComplete: function(responseText) { $('#pool').innerHTML = responseText; } }).send(); 

This is where your responseText will be set to the #pool element.

+1
source

Yes. JSONP is a data type in which a response is sent as an argument to a function. The answer is available in this function.

 $.ajax({ url:"http://localhost:8080/pool/main/?pool=abcd", dataType: 'JSONP', success:function(response){ callFunction(response); }, error:function(){ alert("ERROR"); }, }); function callFunction(data){ $('#pool').innerHTML = data; } 
0
source

Source: https://habr.com/ru/post/1388099/


All Articles