0
This is my json
test and precise, through the keys "ce" and "fortress", perform a search of their respective data. In this case, the search is done by AJAX
which has been subjected to a POST
through a form with two select:
{
"ce": {
"fortaleza": [
{
"nome": "Teste",
"email": "[email protected]",
"cel": "(xx) xx-xx"
},
{
"nome": "Teste",
"email": "[email protected]",
"cel": "(xx) xx-xx"
}
],
"sobral": [
{
"nome": "Teste",
"email": "[email protected]",
"cel": "(xx) xx-xx"
},
{
"nome": "Teste",
"email": "[email protected]",
"cel": "(xx) xx-xx"
}
]
},
"rn": {
"carnaiba": [
{
"nome": "Teste",
"email": "[email protected]",
"cel": "(xx) xx-xx"
},
{
"nome": "Teste",
"email": "[email protected]",
"cel": "(xx) xx-xx"
}
],
"sorisal": [
{
"nome": "Teste",
"email": "[email protected]",
"cel": "(xx) xx-xx"
},
{
"nome": "Teste",
"email": "[email protected]",
"cel": "(xx) xx-xx"
}
]
}
}
Form with example result:
I have no idea how to do this with jquery, because I am completely layman.
Perfect! How do I, when there is a new search, clear the previous one? Thank you.
– Lollipop
What would be "clean" in the case? Return selects to initial state?
– waghcwb
Exactly. It cleans the previous one and queries a new one. That’s all after clicking on Ubmit. Another problem that keeps repeating. I wish I didn’t hear a second consultation in the same
estado+cidade
, but onlyestado+outra cidade
.– Lollipop
To reset a select to set its index to -1 (or any other index you want), like this:
$('select').prop('selectedIndex', -1);
if you prefer you can also insert an input type reset and simulate a click on it. And to disable select will depend on the situation, do you want that after refreshing the page it can select all again? Just use this$('select option').attr('disabled','disabled');
Otherwise you can work withlocalStorage
,sessionStorage
, etc.– waghcwb