php - Problem with Json in Jquery -


I have a small survey, but when I submit it, it says that the message is zero, I Do not know where my error is.

If you can help me then I confirm it.

Thanks

My form with jazzery and ajax function

  & lt ;! DOCTYPE HTML & gt; & Lt; Hmtl lang = "pt-pt" & gt; & Lt; Top & gt; & Lt; Title & gt; Formul & amp; Aacute; Rio & lt; / Title & gt; & Lt; Script type = "text / javascript" src = "http://code.jquery.com/jquery-1.4.2.min.js" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Hour / & gt; & Lt; H3 & gt; Formulario & lt; / H3 & gt; & Lt; Script type = "text / javascript" charset = "UTF-8" & gt; Click on $ (function () {$ ('# submiter'). (Function () {$ .ajax ({type: "POST", url: 'validar.php', datatype: 'Jason', success: function (Msg)) {Warning ('Mensagem' + msg.mensagem);}, Error: function () {Warning ('Okoreu um Arrow');}});});}); & Lt; / Script & gt; & Lt; Form id = "formulario" action = "" method = "post" acceptable-charset = "UTF-8" & gt; & Lt; P & gt; Pergunta 1 & lt; / P & gt; & Lt; Label for = "pergunta1" & gt; SIM & lt; / Label & gt; & Lt; Input type = "radio" id = "p1" name = "pergunta1" value = "1" /> gt; & Lt; Br / & gt; & Lt; Label for "pergunta1" & gt; N & amp; Atilde; O & lt; / Labels & gt; Input type = "radio" id = "p1" name = "pergunta1" value = "0" /> & Lt; Br / & gt; & Lt; P & gt; Pergunta 2 & lt; / P & gt; & Lt; Label for = "pergunta2" & gt; SIM & lt; / Label & gt; & Lt; Input type = "radio" name = "pergunta2" value = "0" /> gt; & Lt; Br / & gt; & Lt; Label = "pergunta2" & gt; N & Eldley; O & lt; / Label & gt; Input type = "radio" name = "pergunta2" value = "1" /> & Lt; Br / & gt; & Lt; P & gt; Pergunta 3 & lt; / P & gt; & Lt; Label for = "pergunta3" & gt; SIM & lt; / Label & gt; & Lt; Input type = "radio" name = "pergunta3" value = "0" /> & Lt; Br / & gt; & Lt; Label = "pergunta3" & gt; N & Eldley; O & lt; / Label & gt; Input type = "radio" name = "pergunta3" value = "1" /> & Lt; Br / & gt; & Lt; P & gt; Pergunta 4 & lt; / P & gt; & Lt; Label for = "pergunta4" & gt; SIM & lt; / Label & gt; & Lt; Input type = "radio" name = "pergunta4" value = "0" /> & Lt; Br / & gt; & Lt; Label = "pergunta4" & gt; N & Eldley; O & lt; / Label & gt; Input type = "radio" name = "pergunta4" value = "1" /> & Lt; Br / & gt; & Lt; P & gt; & Lt; Input type = "submit" id = "submiter" value = "continue & rarr;" & Gt; & Lt; / P & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

My PHP

  & lt ;? Php if ($ _ POST) {$ pergunta1 = $ _POST ['pergunta1']; $ Pergunta2 = $ _POST ['pergunta2']; $ Pergunta3 = $ _POST ['pergunta3']; $ Pergunta4 = $ _POST ['pergunta4']; $ Calculator = $ pergunta1 + $ pergunta2 + $ pergunta3 + $ pergunta4; $ Var = array ('mensagem' = & gt; $ calcular); Echo json_encode ($ var); } And {$ var2 = array ('mensagem' = & gt; 'cm resulted'); Echo json_encode ($ var2); }? & Gt;  

There are two problems with PHP, halfway through you & lt; Php not and . But in fact you should use. Just create a PHP array with your data, json_encode it, and it will do all the clever JSON stuff for you.

Another problem: JSON key string should be.

Try doing something like this:

  $ result = array (); If ($ calcular & lt; = 9) {$ result ['mensagem'] = 1; } // ... e.t.c. Echo json_encode ($ result);  

Edit: I have made a check, and do the following for me:

  $ (document). Ready (function () ($ (.jax) ($ {{type: "POST", url: 'validar.php', datatype: 'jason', success: function (msg) {alerts ('mensagem' + msg. Mensagem);}, error: function () {alerts ('ocureue ur erro');}});});  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -