簡體   English   中英

不同位置頁面之間的HTML傳遞值

[英]HTML Passing Values between pages in different locations

我需要在服務器A上打開一個html頁面,並從服務器B的網頁中獲取一些值。 換句話說,我想在服務器A的網頁上顯示服務器B的網頁值。

我需要這些值的網頁(服務器B)數據由我沒有訪問權限的源填充。 將值寫入看起來像這樣的變量:[[0]]。 訪問該頁面時,該值[[0]]填充有當前數據。

我嘗試將標簽附加到[[0]]失敗,以允許使用表單發布和獲取方法從服務器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>

我為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>

您可以獲取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插件加載服務器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請求。

我之所以說使用節點,是因為該頁面似乎包含必須由JavaScript加載的動態內容。 如果我進一步了解此頁面是如何交互的,那么我將能夠為您的問題提供更具體的解決方案,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM