0
Hi, I’m a little layy with scripts
still. I ask for help, if possible.
I got the following script
:
$.ajax({
type: "POST",
url: "/PreVenda/GuardarPreVenda",
dataType: 'json',
data: JSON.stringify(json),
async: false,//this makes the ajax-call blocking
contentType: 'application/json;charset=UTF-8',
success: function (response) {
alert(response);
window.location.reload().ajax();
valid = response.valid;
},
error: function (error) {
alert(error);
}
});
});
Use the window.location.reload().ajax();
for when saving, it clears all fields on the screen, but when an error occurs on the page, it simply clears the fields too, I just want to clear the fields when everything goes right and not when it goes wrong.
If anyone can help me, I’d appreciate it.
What are you calling that
$.ajax
? You won’t have a<form>
or<a>
what is being called? What is this...reload().ajax()
?– Sergio
This Reload(). ajax() is really weird.
– Brunno Vianna
I call the ajax every time I click the save button, I don’t have a <form> or <a> to be called, that Reload(). ajax() makes all my form clean, but it cleans up until the error, wanted some way to just clean up if everything’s all right.
– Alysson bormann
It seems to me that after the
success
, he wants to re-load the page. But then it doesn’t make sense to re-load using Ajax.– Sam
I tried to use after the
success
call Functionfunction limpiar() {
 $("id_cliente").val("");
 $("nome_cliente").val("");
 $("id_vendedor").val("");
 $("nome_vendedor").val("");
 $("Tot_bruto").val("");
 $("Tot_desc_prc").val("");
 }
Limpar()
, but not clean.– Alysson bormann
@Alyssonbormann You can give an example of which error can appear that also clears the fields?
– Sam
Error if the user does not enter a name, or id, even basic validation, that is being treated within my code and not by script
– Alysson bormann
Missed putting # ->>
$("#id_cliente").val("");
on each of the selectors.– Sam