I have working Ajax call. Now I need to parametrize it as the same Ajax could all different scripts on the server.
I need to
- run different scripts in
xmlhttp.open("GET","/ajaxrun?run=login_build",true);
- name div's in html so the ajax will update correct td
What is the way to do so in Ajax?
I thought
- I would call loadXMLDoc like
<button onclick='loadXMLDoc("login_build")' type='button'>
and then - change the function declaration to
function loadXMLDoc(script, function()
and - change the get call to
xmlhttp.open("GET","/ajaxrun?run="+script,true);
and finally - change the div to
document.getElementById(script).innerHTML=xmlhttp.responseText;
but it doesn't do anything
bit of my html
<script type='text/javascript'>
//<![CDATA[
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
document.getElementById("run").innerHTML=xmlhttp.readyState;
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("run").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/ajaxrun?run=login_build",true);
xmlhttp.send();
}
//]]>
</script>
</head>
<body>
<h1>Available test suits</h1>
<br/><br/>
<table>
<tr>
<td>
<a href='run?run=login_build'>login_build</a>
</td>
<td>
<button onclick='loadXMLDoc()' type='button'>
run
</button>
</td>
<td>
<div id='run'>script results</div>
</td>
</tr>
<tr>
<td>
<a href='run?run=login_cycle_build'>login_cycle_build</a>
</td>
<td>
<button onclick='loadXMLDoc()' type='button'>
run
</button>
</td>
<td>
<div id='run'>script results</div>
</td>
</tr>