通过PHP数组jQuery函数 [英] pass php array to jquery function
问题描述
我有一个网页,一个形式custormers的信息来填充它。我存储在一个PHP数组previous custormers数据。随着一个DropDownList用户可以填写表格与我的存储的数据。
我有什么是触发值更改时和函数内部我喜欢对子级来更新我的存储的数据表单值(在我的PHP数组)jQuery的功能。
问题是,我不知道如何我的PHP数组传递给jQuery的功能,任何想法?
这是我如何填充数组:
$ contador_acompanantes = 0;的foreach($ acompanantes->假面作为acomp中$)
{
$ NUMERO = $ acomp->NÚMERO;
$ apellidos = $ acomp-> Apellidos;
$农布雷= $ acomp->农布雷; $ ACOMPANANTES [$ contador_acompanantes] = $ ficha_acomp;
$ contador_acompanantes ++;
}
得到了我的选择对象:
<选择名称=acompanante_anteriorID =acompanante_anterior>
<期权价值=1选择>Acompañante< /选项>
<期权价值=2> acompanante1< /选项>
<期权价值=2> acompanante2< /选项>
< /选择>
这是我的code为jQuery的功能(这是在同一个PHP页面)
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数()
{
$('#acompanante_anterior')。在('变化',函数()
{ });
});
< / SCRIPT>
VAR arrayFromPHP =<?PHP的回声json_en code($ phpArray); ?取代;
$。每个(arrayFromPHP,功能(我,ELEM){
//做你的东西
});
I got a page with a form to fill it with custormers info. I got previous custormers data stored in a php array. With a dropdownlist users can fill the form with my stored data.
what i have is a jquery function that triggers when the value changes and inside that function i whould like to update the form values with my stored data (in my php array).
Problem is that i dont know how to pass my php array to the jquery function, any idea ??
this is how i fill the array:
$contador_acompanantes = 0;
foreach ($acompanantes->Persona as $acomp)
{
$numero = $acomp->Numero;
$apellidos = $acomp->Apellidos;
$nombre = $acomp->Nombre;
$ACOMPANANTES[$contador_acompanantes] = $ficha_acomp;
$contador_acompanantes++;
}
got my select object:
<select name="acompanante_anterior" id="acompanante_anterior">
<option value="1" selected>Acompañante</option>
<option value="2">acompanante1</option>
<option value="2">acompanante2</option>
</select>
and this is my code for the jquery function (it is in the same .php page)
<script type="text/javascript">
$(document).ready(function()
{
$('#acompanante_anterior').on('change', function()
{
});
});
</script>
var arrayFromPHP = <?php echo json_encode($phpArray); ?>;
$.each(arrayFromPHP, function (i, elem) {
// do your stuff
});
这篇关于通过PHP数组jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!