Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML在不同位置的页面之间传递值_Javascript_Php_Html_Parameter Passing - Fatal编程技术网

Javascript HTML在不同位置的页面之间传递值

Javascript HTML在不同位置的页面之间传递值,javascript,php,html,parameter-passing,Javascript,Php,Html,Parameter Passing,我需要在服务器A上打开一个html页面,并从服务器B的网页中获取一些值。换句话说,我想在服务器A的网页上显示服务器B的网页值 我需要从中获取值的网页(服务器B)数据正在由我无权访问的源填充。这些值被写入一个看起来像这样的变量:[[0]]。访问页面时,该值[[0]]将填充当前数据 我尝试将标签附加到[[0]]以允许使用表单post和get方法从服务器a读取,但未成功 我应该采取什么方法将[[0]]中的数据移动到服务器A网页 服务器B页面: <html> <!-- Head inf

我需要在服务器A上打开一个html页面,并从服务器B的网页中获取一些值。换句话说,我想在服务器A的网页上显示服务器B的网页值

我需要从中获取值的网页(服务器B)数据正在由我无权访问的源填充。这些值被写入一个看起来像这样的变量:[[0]]。访问页面时,该值[[0]]将填充当前数据

我尝试将标签附加到[[0]]以允许使用表单post和get方法从服务器a读取,但未成功

我应该采取什么方法将[[0]]中的数据移动到服务器A网页

服务器B页面:

<html>
<!-- Head information for the page including page title -->

<head>
  <title>Test</title>
</head>

<body color=#FFFFFF>
  <!-- Start of your page body -->
  <!-- This code displays the current tag value for index 0
    [[0]] will be replaced by the tag value a the time the page is loaded -->
  The value of the tag with index 0 is [[0]]
  <!-- Added code to store [[0]] in div -->
  <div class="pink-box" id="thatDiv">[[0]]</div>
</body>

</html>

试验
索引为0的标记的值为[[0]]
[[0]]
我为Server-A添加了这个html/javascript,我得到了COR描述的错误:

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Get Div</title>
  <style>
    body {
      font-size: 12px;
      font-family: Arial;
    }
  </style>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>

<body>
  <b>Div:</b>
  <ol id="Result"></ol>
  <script>
    $("#Result").load("http://192.168.1.168/user/default.html #thatDiv");
  </script>
</body>

</html>

跳伞
身体{
字体大小:12px;
字体系列:Arial;
}
分区:
$(“#结果”)。加载(“http://192.168.1.168/user/default.html #该司);

您可以获取HTML文件的内容,找到起始“[[”和结束“]]”,并获取中间的数据

<?php
$serverBFile = "http://www.serverB.com/file.html";
$serverBHTML = file_get_contents($serverBFile);
$serverBStart = stripos($serverBHTML,"[[");
$serverBEnd = stripos($serverBHTML,"]]");
$serverBLength = $serverBEnd - $serverBStart;   
$serverBValue = substr($serverBHTML, $serverBStart, $serverBLength);
?>

我过去这样做的方式是使用诸如jQuery之类的DOM解析工具

如果您有权访问node.js服务器,则可以使用jQuery插件加载server-B的网页,然后查询具有所需标记的常量,如ID、类名、标记名、位置等

<html>
<!-- Head information for the page including page title -->
<head>
<title>Test</title>
</head>
<body color=#FFFFFF>
<!-- Start of your page body -->
<!-- This code displays the current tag value for index 0
[[0]] will be replaced by the tag value a the time the page is loaded 
let's say [[0]] becomes a <div>-->
<div class="pink-box" id="thatDiv">data I want</div>
</body>
</html> 

试验
我想要的数据
从这里,通过
$('#thatDiv').text()
$('.pink box').text()提取文本相当容易

这是一个相当简单的解决方案。一旦您将该值输入到节点服务器中的变量中,只需公开一个REST调用,您的服务器—一个网页可以向其发出AJAX请求


我之所以说使用node,是因为这个页面似乎有必须用JavaScript加载的动态内容。如果我对这个页面的交互方式有更多的了解,我将能够为您的问题提供更具体的解决方案,

您可以使用curl来解决这个问题,但在我看来,像这样处理html数据有点混乱。。。如果服务器B有一个提要……如果您想从客户端执行此操作,您还可以使用javascript对服务器B进行ajax调用。我将数据放在div中。我可以通过在server-A上执行的节点js和jQuery读取该div吗?还是需要先将div移动到server-B上的javascript变量?感谢您的回复。只要CORS不妨碍您,您可以从任何JavaScript环境中读取div。HTML响应的
Access Control Allow Origin
必须包含发出请求的域,或者设置为
*
。请参阅上面我添加代码以读取DIV的地方。我现在收到您提到的错误:这就是我收到的错误:跨源请求被阻止:同一源策略不允许读取远程资源。这可以通过将资源移动到同一域或启用CORS来解决。您能解释一下我将在何处使用您提到的*修复此错误吗?我似乎通过在加载函数中添加“Access Control Allow Origin”来避免此错误,但来自div的数据仍然没有显示在服务器A中