这不是我给出的问题的实际解决方案。但这是一种使用 PHP 绕过来源的方法。
在我的 javascript 中,我使用以下内容请求了我的 PHP 代码:
function Communication () {
this.global = new Global();
this.allowedParameters = ["Character"];
this.retrieveXMLFromRemoteServer = function (section, keyId, vCode) {
if (this.global.arrayContainsValue(section, this.allowedParameters)) {
$.get(this.formatCommunicationURL(section, keyId, vCode), function(data) {
alert(data);
});
}
}
this.formatCommunicationURL = function (baseUri, keyId, vCode) {
return "server/" + baseUri + ".php?keyId=" + keyId + "&vCode=" + vCode;
}
}
例如:server/Character.php?keyId=00001&vCode=002342345234
The PHP file contains the following code:
<?php
namespace my_api;
class Character {
function retrieveCharacters ($keyId, $vCode) {
return file_get_contents("https://external_url/Characters.aspx?keyId=" . $keyId . "&vCode=" . $vCode);
}
}
$char = new Character();
echo $char->retrieveCharacters($_GET['keyId'], $_GET['vCode']);
?>
This file retrieves the data from the external URL, and then echo's the output so there is a response text JS will be able to use.
Hope this helps for some of you