1
After giving the following command in Javascript:
var dados = $("#form-historico").serialize();
Is it possible to add more information to the object? for example: I would like to send along with the POST data some parameters to recover in PHP file (table, column, etc)...
I tried something like that, but it didn’t work out so well:
var dados = $("#form-historico").serialize();
myPost = {
"dados": dados,
"param": [
{
"crud" : "create",
"table" : "tbl_historicos"
}
]
}
Sending only serialized data and giving a print_r($_POST), print this way in PHP:
Array
(
[hist_peso] => dfs
[hist_altura] => fsf
[hist_pa] => sfsf
[hist_fc] => sfs
[hist_op] => fs
[hist_temp] => fsfsf
[hist_id_paciente] => 3
[hist_id_usuario] => 1
[hist_id] =>
[hist_data_cadastro] =>
[hist_prontuario] => fsfsff
[hist_tratamento] => fsfsfs
[hist_obs] =>
[hist_reacao_alergica] =>
[hist_doenca_contagiosa] =>
[hist_mpa] =>
[hist_etilismo] =>
[hist_tricotomia] =>
[hist_cardiopatia] =>
[hist_protese] =>
[hist_outras_doencas] =>
[hist_jejum] =>
[hist_tabagismo] =>
[hist_diabetico] =>
[hist_insulina] =>
[hist_outros_exames] =>
)
But by including the other parameters in the array and giving a print_r($_POST), print this way:
Array
(
[dados] => hist_peso=&hist_altura=&hist_pa=&hist_fc=&hist_op=&hist_temp=&hist_id_paciente=3&hist_id_usuario=1&hist_id=&hist_data_cadastro=&hist_prontuario=&hist_tratamento=&hist_obs=&hist_reacao_alergica=&hist_doenca_contagiosa=&hist_mpa=&hist_etilismo=&hist_tricotomia=&hist_cardiopatia=&hist_protese=&hist_outras_doencas=&hist_jejum=&hist_tabagismo=&hist_diabetico=&hist_insulina=&hist_outros_exames=
[param] => Array
(
[0] => Array
(
[crud] => create
[table] => tbl_historicos
)
)
)
If anyone can help me or tell me where I’m going wrong???
Yes, very good this example! That way I tried and got, however it concatenates more information in JSON. I needed something to help me separate this information when retrieving in the PHP file, for example: $data = $_POST['data'] and $parametros = $_POST['parameters']... I’ll try here, or it will be via URL even the parameters, but I believe there is a way to do this, I think!!! But thanks for the force...
– RDamazio
I supplemented the answer. Take a look.
– Gato de Schrödinger
@Rdamazio , in this example, you would receive the variables, which you are sending in AJAX, by POST in PHP. Type $_POST['variavel']. That would not be your need ?
– Gato de Schrödinger
Yeah, I just tested your example, it really works. The problem is that I have a class that assembles the SQL statement with the parameters that comes in this POST, in this case it will end up assembling these additional fields too, which in turn do not exist in the database table... Only if I assemble a function to mount the array disregarding these parameter variables neh...
– RDamazio
But you don’t want the variables coming in PHP by Post ? Your question seemed that way...
– Gato de Schrödinger
Yes, I would like to send everything via POST, with the form data as well as the parameters to control in the PHP file
– RDamazio
So this is happening with this code. i am not getting a right understanding of what you would like to do with these values, who arrive by post, in the php file.
– Gato de Schrödinger
If the answer was useful to you, and answered your question explicitly in the question, you can accept by clicking the button located to the left of the answer.
– Gato de Schrödinger
Let’s go continue this discussion in chat.
– Gato de Schrödinger