参考了网上的资料,写了个简单的跨域调用示例:

1.HTML文件:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
function getProfile(str)
{
    var arr =str;//或eval(str)
    document.getElementById('TestName').innerHTML = arr.name;
}
</script>
<body><div ></script>
</html>

注意:

<script type="text/javascript" src="Hello.php"></script>
一定要在Body之后,因为名为TestName的DIV在Body后才可以被调用.

2.PHP文件:

<?php
$arr = array(
'name' => 'garfield',
'nick' => 'Hello',
);
$json_string = json_encode($arr);
echo "getProfile($json_string)";
?> 

 

很简单,但这个技巧很有用.

相关文章:

  • 2021-10-29
  • 2021-06-17
  • 2022-12-23
  • 2022-02-17
  • 2021-07-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-12-08
  • 2022-12-23
  • 2022-01-05
  • 2021-09-23
相关资源
相似解决方案