IMANAZADI
دوشنبه 10 شهریور 1393, 18:12 عصر
با سلام
یک مشکلی واسم پیش اومده
در یک صفحه دو button داریم
میخوام زمانیکه وقتی button 1 کلیک شده تابع a در class.php اجرا بشه و خروجی چاپ بشه و وقتی button 2 کلیک شده تابع b در class.php اجرا بشه و خروجی چاپ بشه
فقط با استفاده از آژاکس (توجه فقط جاوا اسکریپت نه جی کوئری)
صفحه html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function ajax()
{
var xmlhttp=null;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
url='class.php';
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('output').innerHTML=xmlhtt p.responseText;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>
</head>
<body>
<input type="button" value="button 1" onClick="ajax()">
<input type="button" value="button 2" onClick="ajax()">
<div id="output"></div>
</body>
</html>
فایل class.php
<?php
function a()
{
echo 'a';
}
function b()
{
echo 'b';
}
?>
یک مشکلی واسم پیش اومده
در یک صفحه دو button داریم
میخوام زمانیکه وقتی button 1 کلیک شده تابع a در class.php اجرا بشه و خروجی چاپ بشه و وقتی button 2 کلیک شده تابع b در class.php اجرا بشه و خروجی چاپ بشه
فقط با استفاده از آژاکس (توجه فقط جاوا اسکریپت نه جی کوئری)
صفحه html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function ajax()
{
var xmlhttp=null;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
url='class.php';
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('output').innerHTML=xmlhtt p.responseText;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>
</head>
<body>
<input type="button" value="button 1" onClick="ajax()">
<input type="button" value="button 2" onClick="ajax()">
<div id="output"></div>
</body>
</html>
فایل class.php
<?php
function a()
{
echo 'a';
}
function b()
{
echo 'b';
}
?>