2014-01-07 75 views
-1

我需要一些帮助...我有这个网页(http://93.62.201.235/maree/ESPORTAZIONI/MESE/Stazione_PuntaSalute_CanalGrande.html),它在威尼斯创建一个具有高潮值的表格。 我需要一个特定的值(在最后一个原始的第三个单元格),并得到它在一个变量...从外部HTML获取单元格内容通过javascript

我试着用这个jquery代码只看它是否与我在外部html页面中创建的表:

function myFunction() 
{ 

$("#result").load("tableappend.html table", function(){ 
var y = document.getElementById("myTable2").rows[0].cells[0].innerHTML; 
console.log(y); 
}); 

} 

这是“外部”页面的代码:应该写“小区1”上的console.log

<html> 

<body> 

<table id="myTable2" border="1"> 
    <tr> 
    <td>cell 1</td> 
    <td>cell 2</td> 
    </tr> 
    <tr> 
    <td>cell 3</td> 
    <td>cell 4</td> 
    </tr> 
</table> 
<br> 

</body> 
</html> 

,但它不工作... 任何解决方案?

+0

“它不起作用”是什么意思?控制台中有任何错误? –

+0

CORS怎么样? –

+0

没有错误,它没有显示任何内容... – user3161604

回答

1

对于你需要考虑有关CORS(Cross Origin Resource Sharing)

你可以做到这一点使用JSONP JSON的任何跨域请求调用

或发送Origin头为您的请求的一部分。如果双方当事人都同意之间共享,你可以把它成功

UPDATE:

由于您的问题没有解释什么类型的错误,我们承担并给予一定的答案

main.html中

<div id="result"></div> 

tableappend.html

<html> 

<body> 

<table id="myTable2" border="1"> 
    <tr> 
    <td>cell 1</td> 
    <td>cell 2</td> 
    </tr> 
    <tr> 
    <td>cell 3</td> 
    <td>cell 4</td> 
    </tr> 
</table> 
<br> 

</body> 
</html> 

在main.h tml

function myFunction() 
{ 
    //load the tableappend.html page, in the same site under same root 

    $("#result").load("tableappend.html table", 
      function(responseText, textStatus, XMLHttpRequest){ 
      alert(textStatus) // should be success 


    } 
} 
+0

但是如果它是一个跨域错误,OP应该在控制台中出现错误。 –

+0

@ A.沃尔夫,OP甚至没有解释什么错误:( –

+0

雅,真,无聊,我们要问......我的车坏了,该怎么办?该死... –