J'essai depuis 2 jours de récupérer la valeur d'une variable javascript dans mon iframe.
Pouvez vous m'aider svp?
Voici mon code:
<script type="text/javascript">
$(function() {
var flag ;
dataType: 'json';
$("#state").autocomplete({
source: "states1.php",
type: "GET",
data: "param=param",
async: false,
minLength: 2,
success: function(json)
{flag = json.state;
$('#Code1').html(json.Code1);
},
select: function(event, ui) {
$('#state').val(ui.item.Designation);
$('#state_id').val(ui.item.CodeProduit);
$('#sid').val(ui.item.CodeProduit);
$('#abbrev').val(ui.item.Code1);
$('#abbrev2').val(ui.item.Code2);
$("#state_abbrev").focus();
}
});
$("#abbrev2").autocomplete({
source: "states_abbrev1.php",
minLength: 2,
select: function(event, ui) {
$('#state').val(ui.item.Designation);
$('#state_id').val(ui.item.CodeProduit);
$('#sid').val(ui.item.CodeProduit);
$('#abbrev').val(ui.item.Code1;
$('#abbrev2').val(ui.item.value);
$("#state_abbrev").focus();
}
});
$("#abbrev").autocomplete({
source: "states_abbrev2.php",
minLength: 2,
select: function(event, ui) {
$('#state').val(ui.item.Designation);
$('#state_id').val(ui.item.CodeProduit);
$('#sid').val(ui.item.CodeProduit);
$('#abbrev').val(ui.item.value);
$('#abbrev2').val(ui.item.Code2);
$("#state_abbrev").focus();
}
});
});
</script>
echo"<iframe src=dispo.php?Code=json_encode($json['Code1'])></iframe>
Mon code php
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'db';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$term=$_GET["term"];
$query=mysql_query("SELECT * FROM produit where Designation like '%".$term."%' order by Designation ");
if ( ! $query )
die ('mysql_query error SELECT produit' . mysql_error());
$json=array();
$return_json=array();
while($row=mysql_fetch_array($query))
{
$row = array_map('utf8_encode', $row);
$critere = $row['Designation'].' '.$row['Code1'].' '.$row['Code2'];
$json['value'] = $row['Designation'];
$json['Code1'] = $row['Code1'];
$json['Code2'] = $row['Code2'];
$json['sid'] = $row['CodeProduit'];
$json['label'] = $critere;
array_push($return_json,$json);
}
echo json_encode($return_json);
flush();
exit;
?>