Hello friends,
I face to this problem please help me, the array which I return from php file I can not access its element in my ajax code, can you help me plz,
its my php code
<?php
require_once("connection.php");
global $conn;
if (isset($_POST['expGoodsName'])) {
$expCheckSNo=$_POST['expCheckSNo'];
$goodsName=$_POST['expGoodsName'];
$goodsNamequery= mysqli_query($conn,"SELECT S.Quantity, S.Unit, S.UnitPrice FROM tblstock S
INNER JOIN tblimportcheck imp USING(ImpSNo)
INNER JOIN tblexportcheck exp USING(ImpSNo)
WHERE exp.ExpSNO =$expCheckSNo AND S.GoodsName='$goodsName' ");
$rows=mysqli_fetch_assoc($goodsNamequery);
$qty=$rows['Quantity'];
$Unit=$rows['Unit'];
$UnitPrice=$rows['UnitPrice'];
$myArr = array($qty,$Unit, $UnitPrice);
$myJSON = json_encode($myArr);
echo $myJSON;
}
?>
here is ajax code:
$("#expGoodsName").change(function getQuantity(argument) {
sendImportCheck();
});
function sendImportCheck()
{
var XMLHttp;
if (window.XMLHttpRequest) {
// code for modern browsers
XMLHttp = new XMLHttpRequest();
}else {
// code for old IE browsers
XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var expCheckSNo=$("#expCheckSNo").val();
var expGoodsName=$("#expGoodsName").val();
XMLHttp.onreadystatechange=function()
{
if(XMLHttp.status==200 && XMLHttp.readyState==4) {
var myresult= JSON.parse(XMLHttp.responseText);
alert(myresult[0]);//it should display first element
}
}
XMLHttp.open("POST","ExpCheckEdit.php",true);
XMLHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
XMLHttp.send("expCheckSNo="+expCheckSNo+"&expGoodsName="+expGoodsName);
}
What I have tried:
I tried a lot in google but nothing changed