[英]How to interactively get data from php script using javascript
I have this php script: 我有这个php脚本:
<?php
$arr = array(array("a","b"),array("c","d"));
qq($arr);
function qq($arr){
foreach($arr as $ar => $r){
//getting some work done
//sending the array $r (or values)to javascript
}
}
?>
Is it possible to get the value of 0 array using javascript before array 1. 是否可以在数组1之前使用javascript获得数组0的值。
what i get so far is this js from stackoverflow: 我到目前为止所得到的是来自stackoverflow的js:
<script type="text/javascript">
function q(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://127.0.0.0.1/q.php");
xmlhttp.send(null);
xmlhttp.onreadystatechange = callbackFunction;
function callbackFunction(){
if (xmlhttp.readyState == 4){
xml = xmlhttp.responseText;
document.getElementById("q").value = xml;
}}}
</script>
but it's not doing what i want(i think i'm missing something). 但是它没有满足我的要求(我想我缺少了什么)。
my html: 我的html:
<input type="submit" onclick="q();" />
<div id="q"></div>
<div id="q1"></div>
Is it possible to put array 0 value in div(id=q) and when array 1 is ready put it's value in div(id=q1) 是否可以将数组0的值放在div(id = q)中,当数组1准备好时,将其值放在div(id = q1)中
The "normal" HTTP Requests via XMLHttpRequest() do not allow such behaviour in a single request. 通过XMLHttpRequest()的“常规” HTTP请求不允许在单个请求中出现这种行为。
You have the following options instead: 您可以使用以下选项:
Works in all recent browsers. 在所有最新的浏览器中均可使用。 Enables you to do full duplex communication and gets everything right that you need.
使您能够进行全双工通信并正确处理所需的一切。
can you try with 你可以试试吗
if (xmlhttp.readyState == 4){
xml = xmlhttp.responseText;
document.getElementById('q').innerHTML=xml;
}}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.