This is my javascript code:
function getData(param1,param2) {
$.ajaxSetup({async:false});
var request = $.ajax({
url: "http://someurl.com/xyz.php?p1="+param1+"&p2="+param2,
type: "POST",
async: false,
success: function(imageurl){
return imageurl;
}
});
}
and here is the PHP page in which, I am calling this function:
<html>
<head>
<script src="jquery-1.9.1.js"></script>
<script src="http://myjsdomain.com/myjs.js"></script>
<script>
function callMyFunction(box) {
alert(box);
box.value = "Waiting....";
var data = getData('param1', 'param2');
box.value = data;
alert(data); //here I am getting "Undefined"
}
</script>
</head>
<body>
<?=$_SERVER["REMOTE_ADDR"]?><br />
<input type="button" onclick="callMyFunction(this)" value="Click Here" />
</body>
</html>
Now When I am calling this getData()
function in My php page then it returns "Undefined"
.
When I alert data in JavaScript code ,it alerts correct value but still "undefined"
in PHP page.
It is an Ajax ASYNC problem but even after setting it false
, I am still facing this problem.
I debugged it with firebug and I can see that the URL (from where I am getting the data using ajax) is returning correct value but it is not receiving on PHP page where I am calling this function.
Any suggestions to make this work