[英]External javascript call php for widget?
我希望用户可以包含我的php文件并从某个类的文件中加载内容。
例如,假设用户拥有此文件: user.html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="myfile.php?width=100&height=100">
</script>
</head>
<body>
<div class="my-class">
</div>
</body>
</html>
我希望从.my-class中的 myfile.php中显示一些内容:
<?php
$width = $_GET['width'];
$height = $_GET['height'];
echo "$('.my-class').load('load_content.php?width=$width&height=$height')";
?>
并且在load_content.php
中现在很简单:
<?php
echo $_GET['width'] + $_GET['height'];
?>
我无法在任何地方找到类似的问题,我尝试了一些东西,但只有我成功的是document.write user.html来自myfile.php的东西,但当我尝试加载东西或使用innerHTML我得到空白页。
我想你正在尝试使用<script>
标签进行ajax调用。 这是你应该做的事情,因为你的页面上已经包含了jquery:
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> </head> <body> <div class="my-class"> </div> <script> $(document).ready(function(){ $.get('load_content.php?width=100&height=100') .done(function(resp){ $('.my-class').html(resp); }) .fail(function(){ $('.my-class').html('<h2>There was an error loading content</h2>'); }); }); </script> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.