How would i get a html code generated by php script on a different domain. people suggest me to use JSONP. I read a lot of JSONP aticles but all of them only get data in this format:
callback({"name" : "Remy","id" : "123"}
BUT , my php script generates HTML code not the data as shown above. Normally if i'm on the same domain (the javascript and php scripts) , i will use Ajax to do the job like this:
$.ajax({
type: 'GET',
url: 'user.php',
data: 'user_id=user_id', //assuming user_id value was already set.
success: function(html)
{
$('#info').empty().html(html);
}
});
Now , my javascript is on a different domain than my php script. How would i get the html generated by the php scripts using javascript(jQuery , Ajax JSON???) ?
Or am i missing something in JSONP?
JSONP, as the name implies, is for JSON .
What you can do is turn your HTML into valid JSON (just use json_encode()
in your PHP script, passing it your HTML string) and then load the HTML out of that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.