In a page I have this field filled with the value "SP"
<input id="campo" value="SP">
In php I have parameter
<?php
echo $_POST['estado'];
?>
To process this field via ajax I would use
var valor=$('#campo').val();
in the ajax request,
data: {estado: valor},
What I want is to pass this 'state' parameter also inside a variable
var string="estado";
so that in the ajax request it looks like this:
data: {string : valor},
My code
<script type="text/javascript">
$(document).ready(function () {
var string="estado";
var valor=$("#campo").val();
ajsjax(string,valor);
});
</script>
function ajsjax(string,valor){
$.ajax({
type: "POST",
dataType: "html",
url: "postos/cadastro_pegar_items.php",
data: {string : valor} , //as informações nao chegam aqui da forma correta
success: function(data){
alert(data);
}});
}