简体   繁体   English

使用Phantomjs / Jquery发送Crossdomain GET请求服务器端

[英]Send a Crossdomain GET request Server Side with Phantomjs/Jquery

Is there a way to incorporate 有没有办法融入

$.get("http://localhost/?action=post", { site: "Test" } );

On the server side with PhantomJs and Jquery? 在PhantomJs和Jquery的服务器端?

includeJs() and injectJs() don't seem to do anything but throw errors. includeJs()和injectJs()似乎没有做任何事情,只是抛出错误。

Also: 也:

I have tried using regular Javscript on the server side, too: 我也试过在服务器端使用常规的Javscript:

var xhr = new XMLHttpRequest();
var page = "http://localhost";
var params = "action=post&site=ipsum";
xhr.open("GET",page+"?"+params, false); 
xhr.send();

No luck that way either: 也没有运气:

    xhr.open("GET",page+"?"+params, false); 

Notice how I have the third parameter, async, set to "false"--- nothing happens when set to "true"! 注意我如何将第三个参数async设置为“false”---设置为“true”时没有任何反应!

Any ideas? 有任何想法吗?

一个快速的谷歌告诉我他们支持跨域请求与命令行--web-security=false在这里找到https://github.com/ariya/phantomjs/wiki/API-Reference

I can't add comment to DMoses's answer, so I share my opinion as an answer here. 我不能对DMoses的回答添加评论,所以我在这里作为答案分享我的意见。

To translate web security setting mentioned by DMoses, you can use phantomjs --web-security=no yourjsfile.js . 要翻译DMoses提到的Web安全设置,您可以使用phantomjs --web-security=no yourjsfile.js

Notice, this syntax works under macOS, but not viable within Ubuntu 16.04; 请注意,此语法在macOS下工作,但在Ubuntu 16.04中不可行; with web security disabled in phantomjs execution, ubuntu still gives out 'CORS not supported' error. 如果在phantomjs执行中禁用了web安全性,ubuntu仍然会发出'CORS not supported'错误。 I am wondering if the option --web-security=no is not working under Ubuntu. 我想知道选项--web-security=no是否在Ubuntu下不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM