I have a html form with a button on which there is a onclick event
<form id = "abc" action = "xyz.php" method = "post">
<input type="button" name="submitButton" value="Submit"
id="submitButton" onclick = "Function()">
</form>
In the JS code, I am trying to post a value of a textbox and trying to get the array from the PHP through json_encode.
var valueToSend = $('#textbox').val();
var imagesReturned = new Array();
$.ajax({
url: "xyz.php",
type: "POST",
data: valueToSend,
dataType:"json",
success: function(result) {
var data = jQuery.parseJSON(result);
alert(data);
}
});
And here is my PHP code,
if(isset($_POST['valueToSend']))
{
$searchValues = explode(' ',$_POST['valueToSend']);
// Some processing here
echo (json_encode($responseArray));
}
When I alert the data, I get null, What am I missing?
Thanks!