[英]How to get html code generated by php using JSONP from another domain?
How would i get a html code generated by php script on a different domain. 我如何在不同的域上获取由php脚本生成的html代码。 people suggest me to use JSONP. 人们建议我使用JSONP。 I read a lot of JSONP aticles but all of them only get data in this format: 我读了很多JSONP顶点,但是它们都只能以这种格式获取数据:
callback({"name" : "Remy","id" : "123"}
BUT , my php script generates HTML code not the data as shown above. 但是,我的php脚本生成HTML代码,而不是上面显示的数据。 Normally if i'm on the same domain (the javascript and php scripts) , i will use Ajax to do the job like this: 通常,如果我在同一域(javascript和php脚本)上,则我将使用Ajax来完成以下工作:
$.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. 现在,我的JavaScript与PHP脚本位于不同的域。 How would i get the html generated by the php scripts using javascript(jQuery , Ajax JSON???) ? 我如何获取使用javascript(jQuery,Ajax JSON ???)的php脚本生成的html?
Or am i missing something in JSONP? 还是我在JSONP中缺少某些内容?
JSONP, as the name implies, is for JSON . 顾名思义,JSONP用于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. 您可以做的是将HTML转换为有效的JSON(只需在PHP脚本中使用json_encode()
,然后将其传递给您的HTML字符串),然后从中加载HTML。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.