ajax从php页面调用变量的值
我是javascript新手,我到处都在搜索这个问题,但没有合适的答案。 我有一个“code.php”页面 在“index.php”的另一面,我有ajax从php页面调用变量的值,php,ajax,Php,Ajax,我是javascript新手,我到处都在搜索这个问题,但没有合适的答案。 我有一个“code.php”页面 在“index.php”的另一面,我有 “数字的值为:” 函数myFunction(){ document.getElementById(“myText”).innerHTML=$row[1]; } 我想将$row[1]的值从code.php加载到index.php 我知道我必须使用ajax,但如何使用?在索引php中,使用ajax从php代码中获取数据。 例如: <script&
“数字的值为:”
函数myFunction(){
document.getElementById(“myText”).innerHTML=$row[1];
}
我想将$row[1]
的值从code.php
加载到index.php
我知道我必须使用ajax,但如何使用?在索引php中,使用ajax从php代码中获取数据。 例如:
<script>
$.ajax({
url: 'code.php',
type:'get',
success:function(data){
$("#myText").html(data);
}
});
</script>
$.ajax({
url:'code.php',
类型:'get',
成功:功能(数据){
$(“#myText”).html(数据);
}
});
$(文档).ready(函数(){
$.ajax({
类型:'get',
url:'code.php',
成功:功能(响应){
//ajax将把code=,php的结果分配到响应中
document.getElementById(“myText”).innerHTML=response;//response;
}
});
});
将其放在index.php的标题处
您可以在网上找到更多教程,以更好地了解ajax
别忘了下载jquery并将其嵌入到您的代码中
或者你可以复制这个
您可以使用jquery,.No,它不返回任何内容。它只是说“数字的值是:”
<h1>"the value for number is: " <span id="myText"></span></h1>
function myFunction() {
document.getElementById("myText").innerHTML = $row[1];
}
<script>
$.ajax({
url: 'code.php',
type:'get',
success:function(data){
$("#myText").html(data);
}
});
</script>
<script>
$(document).ready(function(){
$.ajax({
type:'get',
url:'code.php',
success:function(response){
// ajax will assign the result of code =,php into response
document.getElementById("myText").innerHTML = response; //response;
}
});
});
</script>