ricardocoimbra Posted August 21, 2013 at 04:24 PM Report #522283 Posted August 21, 2013 at 04:24 PM (edited) Boa tarde, Não sei como passar um array por ajax estou a utilizar o jquery será que alguem me pode ajudar. Neste exemplo os valores nome e telefone consigo enviar acontece que nao consigo é enviar o array -> camposMarcados. Ou seja neste caso quero enviar da checkbox o valor 100 e 165 que sao os que estao seleccionados. eu tenho isto: <script type="text/javascript"> $(document).ready(function(){ $('#enviar').click(function () { var nome = $('#nome').val(); var telefone = $('#telefone').val(); camposMarcados = new Array(); $("input[type=checbox][name='ans[]']:checked").each(function(){ camposMarcados.push($(this).val()); var dataString = 'nome='+ nome + '&telefone=' + telefone+'&camposMarcados =' + camposMarcados; $.ajax({ type: "POST", url: "registar.php", data: dataString, success: function() { alert('Enviado'); } }); }); }); </script> <input type="text" name="nome" id="nome" /> <input type="text" name="telefone" id="telefone" /> <input type="checkbox" id="ans" name="ans[]" value="100" checked="checked"> <input type="checkbox" id="ans" name="ans[]" value="165" checked="checked"> <input type="checkbox" id="ans" name="ans[]" value="70"> <a href="javascript:void(0)" id="enviar">Enviar mensagem</a> Edited August 21, 2013 at 05:22 PM by ricardocoimbra
ricardocoimbra Posted August 21, 2013 at 05:22 PM Author Report #522289 Posted August 21, 2013 at 05:22 PM resolvido....
NunoDinis Posted August 21, 2013 at 06:54 PM Report #522300 Posted August 21, 2013 at 06:54 PM $.ajax({ type: 'POST', url: 'FICHEIRO.php', data: { campo1: valor, camp2: valor }, success:function(data){ alert('ok'); }, error:function(error){ alert('ko'); } }); Estranha forma de vida que tem a capacidade de transformar comandos em mensagens de erro. ndsotware.org
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now