array in javascript that communicates in php

2

I need to create a array in tag that is submitted your information to a page .

How can I do this?

Next, I had a that I uploaded, repeated data from the bank. So to improve her performance, I've created a script in I copied the contents of the tables. But each table has a option and every option has a selected , so I need every option to start as its specific phrase, just like the whole pg in . For this I did the script below:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><script>$(document).ready(function(){//frasequedesejolocalizarvarfrase="minAlarme4_analogico00",
        localizado = null;

    // loop que percorre cada uma das opções
    // e verifica se a frase da opção confere com o
    // valor de fase que está sendo procurado
    // valor de fase que está sendo procurado
    $('#Linha5 option').each(function() {
      // se localizar a frase, define o atributo selected
      if($(this).attr('value') == frase) {
        $(this).prop('selected', true);
      }
    });
});
</script>

However (minAlarme4_analogico00 ") is the name of a sensor and I have type 1500. So I need an array to communicate with the tag so that the same get the names of the sensors.

    
asked by anonymous 05.03.2014 / 15:12

1 answer

2

You can use JSON.stringify(array) in JavaScript to encode the array and send it to PHP, where you use $array = json_decode($_POST['dados']); to read the passed variable.

If you want to do something dynamically, you should use AJAX , which would look something like this: / p>

No JS

meuArray = ??? ;
var arrayCodificado = JSON.stringify(meuArray);
$.ajax({
    type: "POST",
    url: "script.php",
    data: { dados: arrayCodificado }, 
    cache: false,
    success: function(){
        alert("Feito!");
    }
});

In PHP

$meuArray = json_decode(stripslashes($_POST['dados']));
foreach($meuArray as $d){
    echo $d;
}
    
05.03.2014 / 17:16