Here’s what I am trying to do.
I have the following script which will POST data from index.php on the same page(index.php):
<script type="text/javascript">
function loadabc(){
var optionValue = jQuery("select[name='citycountrystores']").val();
jQuery.ajax({
type: "POST",
url: "index.php",
data: ({result: optionValue}),
success: function(response){
jQuery("#cityAjax").html(response);
jQuery("#cityAjax").show();
}
});
I want to access the POST data in php.
The php statements are written in the same javascript.
I need to access $_POST[‘result’] in a php if statement like:
<?php
if($check==$_POST['result'])
{
code....
.........
}
?>
}//Function loadabc end
</script>
This is my select box
<select id="citycountrystores" name="citycountrystores" onchange="loadabc();">
<option value="76">City1</option>
<option value="77">City2</option>
<option value="78">City3</option>
</select>
I can see the POST value(76 or 77 or 78) in the console. But i would like to know how to store it in a php variable for immediate access.
Can someone please tell me how I can do this, or any other approach to achieve this.
If you want to access same page from
AJAXyou need to end your script before it prints the rest of the page out, first lines in code should be: