<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<form>
<label>Seleziona l'ente</label>
<select name="data" id="data">
<option value="PRO - 011142764">COMUNE DI AGLIE'</option>
<option value="PRO - 011120674">COMUNE DI AGRATE CONTURBIA</option>
</select>
<input type="text" name="textfield" id="textfield" />
</form>
<script>
$('#data').change(function() {
$.post("richiesta.php", { value: this.value });
$('#textfield').val(this.value);
});
</script>
</body>
</html>
Here's my simple web page with 2 options. The input tag is just for testing the POST data.
Here's richiesta.php
, that receives the POST data on change event (I followed this thread):
<?php
list($comparto, $ente) = explode("-", $_POST['data'], 2);
echo "comparto: $comparto, ente: $ente";
?>
Here's what happens when I trigger the change event (from Firebug). POST is ok:
Unfortunately the response has empty variables ($comparto
and $ente
):
What's the problem with the explode
/list
function?