You can make the transfer in json format
<?php $a = "10"; $b = "20"; $arr = array('a' => $a, 'b' => $b); echo json_encode($arr); /// {"a":"10", "b":"20"} ?>
Further in js to process as object. For example, if you use jQuery, then
$.getJSON("Test.php", function(data){ $("#a").html(data.a); $("#b").html(data.b); }); });
Another syntax error in html
<!-- Имена идентификаторов должны начинатся с латинской буквы http://htmlbook.ru/html/attr/id --> <div id='a'></div> <div id='b'></div>
Well, if not jquery, then you can process the received request as
function LoadDiv(){ var req = getXmlHttp(); req.onreadystatechange = function() { if (req.readyState == 4) { if(req.status == 200) { var a = req.responseText; eval("b = "+a); if(typeof b == 'object') { d = document; d.getElementById('a').innerHTML = ba; d.getElementById('b').innerHTML = bb; } else { alert("Error: "+a) } } else { alert("Error: "+xmlhttp.statusText); } } } req.open('GET', 'Test.php'); req.send(null); }
Addition: what variable? If about b, then it is an object:
- The answer comes from the server {"a": "10", "b": "20"}
- This answer is declared in the variable a
- Using the argument of the eval function, we create the expression b = {"a": "10", "b": "20"} and accordingly ealym it
- We have an object b with the values b = {"a": "10", "b": "20"}
- Check if the server actually returned an if object (typeof b == 'object')
- Now this object is used (ba = 10 and bb = 20) to insert into the div elements on the d.getElementById ('a') page. InnerHTML = ba; and d.getElementById ('b'). innerHTML = bb; (for reference, instead of "1" and "2" I used divas "a" and "b")
- ??????
- PROFIT
Pruflinki: http://javascript.ru/eval http://javascript.ru/tutorial/object/intro http://ru.wikipedia.org/wiki/JSON
if the variables need to be added more in the array in php as many as you like and then we take them out in javascript all of the above.