Reputation: 4896
I have a form something like this
<form id="logReg" action="<?php echo $url?>" method="post">
<input name="im_user" type="text" class="valores" id="im_user" placeholder="Email" style="height:35px; font-size:16px;" maxlength="255" />
<input name="im_password" type="password" class="valores" placeholder="Contraseña" style="height:35px; font-size:16px;" id="im_password" />
<input name="inputAds" type="submit" value="Ingresar" />
</form>
Its a login form . Then I am using Post() method of Jquery to send the login details to the server everything working fine . But the problem is in the console when i debug the response of the post method . I see the my password and id is visible.
Ajax script is
$("#logReg").submit(function (event) {
// Stop form from submitting normally
event.preventDefault();
console.log("request being sent");
// Get some values from elements on the page:
var $form = $(this),
im_user = $form.find("input[name='im_user']").val(),
im_password = $form.find("input[name='im_password']").val(),
url = $form.attr("action");
// Send the data using post
var posting = $.post(url, {
im_user: im_user,
im_password: im_password
});
//Put the results in a div
posting.done(function (data) {
var content = $(data).find("#content");
$("#logRegResult").empty().append(content);
});
});
I am very new to Ajax method . Can any one explain me how can I hide the password and id from displaying in the console .
Thanks
Upvotes: 0
Views: 304
Reputation: 4560
When you assign some value to a variable, the left hand code is executed, then that final value is assigned to the variable.
In this case it's the jQuery post object which has already sent a request, with out a specified callback. You should specify the callback like so.
var posting = $.post(url, {
im_user: im_user,
im_password: im_password
}).done(function (data) {
var content = $(data).find("#content");
$("#logRegResult").html(content);
});
* Note: as others have mentioned, this is not a secure method for sending your passwords.
Also, it seems a little odd to me to be looking for an element by id with-in the return data. Make sure that part is actually functioning. You probably want the html to be properly formatted before it's sent back from the server.
Upvotes: 1