سلام
وظیفه ajax نویسی برعهده چه کسی هست؟ فرانت کار یا بک اند کار؟
با سلام خدمت شما همراه عزیز
بستگیبه نوع پروژه داره ولی معمولا هر دو
چون شما باید یکسری اطلاعات رو دراختیار فرانت قرار بدید
salam ostad bbakhshid tu dore php pishrafte k mashin hesab sadaro neveshtin nmidunam chera result baram neshun nmide mishe lotfan ru code ham y negahi bndazid?
salam ostad bbakhshid tu dore php pishrafte k mashin hesab sadaro neveshtin nmidunam chera result baram neshun nmide mishe lotfan ru code ham y negahi bndazid?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
No1: <input type="text" id="no1">
<br>
No2: <input type="text" id="no2">
<br>
<button type="button" onclick="calc('add')">+</button>
<button type="button" onclick="calc('sub')">-</button>
<button type="button" onclick="calc('mult')">*</button>
<button type="button" onclick="calc('div')">/</button>
<br>
<br>
Result: <span id="result"></span>
<script>
function calc(reqType){
var xhr=new XMLHttpRequest();
var no1= document.getElementById("no1").value;
var no2= Document.getElementById("no2").value;
xhr.onreadystatechange= function(){
if (xhr.readyState==4 && xhr.status==200) {
document.getElementById("result").innerHTML=xhr.responseText;
}
}
xhr.open("Get","print.php?req="+reqType+"&n1="+no1+"&n2="+no2,true);
xhr.send();
}
</script>
</body>
</html>
<?php
$nom1=$_REQUEST["n1"];
$nom2=$_REQUEST["n2"];
$req=$_REQUEST["req"];
if ($req=="add") {
echo $nom1 + $nom2;
}
elseif ($req=="sub") {
echo $nom1 - $nom2;
}
elseif ($req=="mult") {
echo $nom1 * $nom2;
}
elseif ($req=="div") {
echo $nom1 / $nom2;
}
?>
با سلام خدمت شما همراه عزیز
با کدهای بنده مقایسه کنید