问题描述
应该使用站点号1请求到站点号2.使第一个站点为localhost,站点号2为Internet上的真实服务器。在站点2有一个文件result.php,它需要GET请求:
Should be done with the site number 1 request to the site number 2. Let the number one site will be localhost, and the site number 2 - the real server on the Internet. At site 2 there is a file result.php, which takes GET-requests:
$ var = @ $ _ GET [ q'];
$ s = $ _GET ['s'];
$ typefile = $ _GET ['type'];
如果页面result.php提出请求,那么我们获取URL:result.php?q =%F4%FB% E2& type = 1& search =%CF%EE%E8%F1%EA%21
$var = @$_GET['q'] ;
$s = $_GET['s'] ;
$typefile = $_GET['type'];
If the page result.php make a request, then we obtain the URL: result.php?q=%F4%FB%E2&type=1&search=%CF%EE%E8%F1%EA%21
如何更好地提出请求?有人可以告诉我一些例子来帮助吗?
How better to make a request? Can someone show me some examples to help? For 4 days I suffer, does not realize.
如果某个地方不清楚,请用英文。
If somewhere is not clear written excuse my bad English with.
推荐答案
我假设你是指Ajax?由于,您无法通过正常的ajax进行跨网站域请求。因此,localhost上托管的脚本只能向localhost发出请求。
I'm assuming you mean with Ajax? You can't make cross-site domain requests through normal ajax due to the same origin policy. As such, a script hosted on localhost, can only make requests to localhost.
现在,您可以使用,或带有填充的JSON。这允许您从任何源附加脚本文件到dom,以便代码可以在您的网站上执行。个人来说,我实际上从来没有使用它,我知道你必须信任脚本的来源,你不想在你的网站上运行任意代码。
Now, you can get around this with JSONP, or JSON with padding. This allows you to append a script file to the dom from any source so the code can execute on your site. Personally, I've actually never used it and I understand you have to trust the origin of the script, you don't want arbitrary code being run on your site.
简而言之,如果你想让localhost向site-2发出请求,你需要在site-2上托管一个由你的localhost加载的脚本并提出请求。
So in a nutshell, if you want localhost to make a request to 'site-2' you need to host a script on 'site-2' that gets loaded by your localhost and makes the request.
这篇关于跨网站请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!