Answer the question
In order to leave comments, you need to log in
JSONP how to organize getting html in callback?
Good afternoon, the situation is as follows: I want to build a registration form on my third-party site. Since I don't want to mess around with CORS, I decided to make requests via jsonp get. The apishka itself receives data in the controller. Depending on them, it builds a form and displays it through the view along with the entire layout Html page. The form itself already sends data for registration (transferring data via jsonp without a response through the callback works properly).
Connecting a script on a third-party site
<script id="jsonp_script" src="https://somesite.com/assets/js/api/test.js?login=1&email=1&password=1"></script>
var res = $.ajax({
url: "https://somesite.com/test",
method: "GET",
data: fields, //массив из полей, которые были true
dataType: "jsonp",
jsonp: "callback",
contentType: "application/json; charset=utf-8",
success:function(response){
$("#some").append(response);;
}
});
res.done(function( msg ) {
alert(msg);
});
Answer the question
In order to leave comments, you need to log in
I understand correctly, the response comes with HTML? If so, then therein lies the problem.
You indicated that you are expecting a jsonp response from the server , but you are receiving HTML.
If you need to get HTML, the dataType must be set to html
.
In general, I would recommend getting confused with CORS, everything is not as complicated as it might seem.
https://learn.javascript.ru/xhr-crossdomain
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question