2
I need to fill in my fields after selecting a.
My JSON is as follows:
[{"codeVisit":"3EE","segmentVisit":"industria","streetVisit":"Rua Francisco Leandro Cunha","neighbVisit":"Vila","countryVisit":"Brasil","client":"5580262b600e53e82069bbeb"}]
And it’s at the address: /clienteJson
I have the fields with the names below in my HTML(input text
, except the client which is a select
):
The field client
is a select
and after selecting it, I need the other data to be automatically loaded.
I’m making a script as follows:
$(document).ready(function(){
$("select[name='client']").change(function(){
var codeVisit= $("input[name='codeVisit']");
var segmentVisit = $("input[name='segmentVisit']");
$(codeVisit).val('Carregando...');
$(segmentVisit).val('Carregando...');
$.getJSON(
"/clienteJson"
{ client: $( this ).val() },
function( json )
{
$( codeVisit ).val( json.codeVisit );
var s = $( segmentVisit ).val( json.segmentVisit );
console.log(s)
}
);
alert("erro")
});
});
But fields are not loaded.
What can I do?
I’m using nodejs and Mongoose.
You looked at the Javascript console to see the error message?
/clienteJson
should be a string, and should be succeeded by a comma.– user25930
Besides what @ctgPi said, I also didn’t understand why you take inputs and arrow loading
– Maicon Carraro
Now I noticed also that your json starts
[{"codeVisit":3EE, …
; are missing quotes around3EE
. How exactly are you generating this JSON there on the server?– user25930
The json is correct, I edited and forgot to include the quotation marks of 3EE, but the json has. and about the /clientJson, I put in ''" and comma. Still it didn’t work. The big problem is that my Json file mounts all the information (if it has 200, it mounts 200 arrays) . When sending {client: $(this). val}, it searches for the specific ID, so much so that the error in the console is: http://localhost:3000/clientJson? client=5580262b600e53e82069bbeb Not Found.... I wanted to know how to find the information and my json brings everything.
– Nodejs
I see you’re correcting code errors... is the rest of the code what you’re using? or is it sample code? For example
client: $( this ).val() },
is wrong... the problem is described here: http://answall.com/a/3325/129– Sergio
I just fixed it. Now it’s okay! Yes the problem is with the client: $( this ).val() because as I said my Json file, the url opens with all the data... I did not create a URL with ID. and this client:$(this), searches the id . I wanted to know how to search the data, without having to pass this ID. That is, when I select(select client), search in my json file the data and fill the others.
– Nodejs