Hi i would like to create a confirm password validation with jquery ajax. I dont know how to put multiple variables in data attrib
function checkPwdRepeat() {
jQuery.ajax({
url: "check_availability.php",
data: 'pwdRepeat=' + $("#pwdRepeat").val(),
data: 'pwd=' + $("#pwd").val(),
type: "POST",
success: function(data) {
$("#check-pwdRepeat").html(data);
},
error: function() {}
});`your text`
}
```
Related
I am inserting the data into the database and display data on the page without refresh the page.
I tried $("#e-empListwrap").load(location.href + "#e-empListwrap"); but it's displaying the whole page on my page.
$("form[name='emp']").validate({
rules: {
//rules
},
submitHandler: function(form) {
var form = $('form[name="emp"]').get(0);
var formData = new FormData(form);
$.ajax({
url: baseUrl + "/controller/emp_control.php",
type: "POST",
dataType: 'json',
data: formData,
contentType: false,
cache: false,
processData: false,
success: function(data) {
$('form[name="emp"]')[0].reset();
$('#modal-addemp').modal().hide();
$("#e-empListwrap").load(location.href + "#e-empListwrap");
},
}); // AJAX Get Jquery statment
}
});
HTML
<div class="e-empListwrap mt-4" id="e-empListwrap"><ul></ul></div>
// The below is the script when refersh the page then it will call the ajax and get the the and display on the page.
<script>
fetchEMPsaved_data();
function fetchEMPsaved_data(){
$.ajax({
url:'controller/developer_control.php',
type: "post",
dataType: "json",
data: { action: "fetchEMPsaved_data"},
success: function(data) {
$("#e-empListwrap ul").append(data);
}
});
}
</script>
You are missing a space after the url, between the url and CSS target:
$("#e-empListwrap").load(location.href + " #e-empListwrap");
or else jquery handles it as an anchor of the url, not as the element ID. You are loading url.html#element but to grep an element/css target, not the whole page, the syntax should be url.html #elementOrTarget, with the space in between.
I am writing a thing to compare two passwords with each other, if they match the script sends out a response that says it is the same.
I currently have got this code:
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data: "'password1'='" + $("#Password").val() + "', 'password2'='" + $("#repeatPw").val() + "'",
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Now my problem is that i cant get this password1 and password2 in a proper array i can explode in the checkPasswords.php, this posts this:
Array ( ['password1'] => 'fasfasdfasSD2', 'password2'='asdasdasd' )
But this is not a proper array as it only puts password1 in proper array format, how would i go about making password2 in this format too?
Thank you all in advance!
You can do it with a FormData object:
$("#repeatPw").keyup(function(){
var fd = new FormData();
fd.append('password1', $("#Password").val());
fd.append('password2', $("#Password").val());
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data: fd,
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Or do it the JSON way:
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data :{
password1: $("#Password").val(),
password2: $("#repeatPw").val(),
},
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Create an array and pass it as the ajax post data,
var data=[];
data['password1']= $("#Password").val();
data['password2']= $("#repeatPw").val();
Though you could do this in the client side itself.
if($("#Password").val().trim() == $("#repeatPw").val().trim())
//password Matches
Hopes this help u..
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data :{
password1: $("#Password").val(),
password2: $("#repeatPw").val(),
},
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
Try like this
$("#repeatPw").keyup(function(){
jQuery.ajax({
url: "System/Javascript/Functions/checkPasswords.php",
data: {'password1' : $("#Password").val(), 'password2' : $("#repeatPw").val() },
type: "POST",
success: function(data) {
$("#passwordMatch").html(data);
},
error: function(data) {}
});
});
I'm calling php file through ajax call and if it returns nothing i want to redirect user to another page (It's for error reports, if it doesn't return anything it means that user logged in). Tried to add error section but it doesn't work. Any suggestions will help. Thanks! Btw, I have small jQuery function at the top of the ajax function, why it breaks my whole ajax call?
ajax.js
function loginAjax() {
//$("#email_errors").empty(); //This function doesnt work and kills whole ajax call. Here is loginAjax function call line - <button type = "submit" id = "push_button" onclick = "loginAjax(); return false">PushMe</button>
$.ajax({
url: "Classes/call_methods_login.php",
type: "POST",
dataType: "json",
data: {
login_email: $("#login_email").val(),
login_password: $("#login_password").val(),
},
success: function(data) {
$("#login_error").html(data.login_message);
}
});
}
$.ajax({
url: "Classes/call_methods_login.php",
type: "POST",
dataType: "json",
data: {
login_email: $("#login_email").val(),
login_password: $("#login_password").val(),
},
success: function(data) {
$("#login_error").html(data.login_message);
},
error: function(){
window.location.replace("http://stackoverflow.com");
}
});
}
To redirect using javascript all you need to do is override the location.href attribute.
function loginAjax() {
$.ajax({
url: "Classes/call_methods_login.php",
type: "POST",
dataType: "json",
data: {
login_email: $("#login_email").val(),
login_password: $("#login_password").val(),
},
// the success method is deprecated in favor of done.
done: function(data) {
$("#login_error").html(data.login_message);
},
fail: function(data) {
location.href="path/to/error/page";
}
});
}
in my application I have to make an ajax call to php file.it works proper in all devices. but when I tried it on ipad mini it not calls the php, so that the functionality not works, I've seen so many question about this problem and edited my code like this.
jQuery.ajax({
type: "POST",
async: true,
cache: false,
url: "directory/phpfile.php",
data: data,
success: function(response) {
}
});
my old code is
jQuery.ajax({
type: "POST",
url: "wp-admin/admin-ajax.php",
data: data,
success: function(response) {
}
});
and the problem still cant resolve . so please any one tell me how to resolve this.
Please use this code
$("#ajaxform").submit(function(e)
{
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
$.ajax(
{
url : formURL,
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR)
{
//data: return data from server
},
error: function(jqXHR, textStatus, errorThrown)
{
//if fails
}
});
e.preventDefault(); //STOP default action
e.unbind(); //unbind. to stop multiple form submit.
});
$("#ajaxform").submit(); //Submit the FORM
<script type='text/javascript'>
$(document).ready(function startAjax() {
$.ajax({
type: "POST",
url: "test.php",
data: "name=name&location=location",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
});
I'm building a PhoneGap app where user press button which then sends data to server. On the success handler I have a new function that asks user some questions with prompt box and then sends them back to server. So I need to make the prompt box appear as long as the condition "status=ok" is true.
I don't know how many times the prompt box has to appear, it can be anything from 1 to 10 times, so I guess I need to make a some sort of loop, but how can I do it?
This is the code I've been using now:
function UpdateRecord(update_id)
{ var id = getUrlVars()["id"];
jQuery.ajax({ type: "POST",
url: serviceURL + "update.php",
data: 'id='+id ,
cache: false,
success: function(data) {
console.log(data)
if(data.key[0].status == "ok"){
var reply = prompt(data.key[0].QUESTION, "");
jQuery.ajax({ type: "POST",
url: serviceURL + "question.php",
data: 'id='+id+'&reply='+reply ,
cache: false,
success: function(data) {
window.location = "page.html" }
} else {
window.location = "page.html"
}
}
});
}
I think what your after is moving the response from the AJAX call into a method AskQuestion (or whatever you want to call it). This function would prompt and would query if the answer was correct or not and redirect them to another page:
function AskQuestion(data)
{
var id = getUrlVars()["id"];
console.log(data);
if(data.key[0].status == "ok") {
var reply = prompt(data.key[0].QUESTION, "");
jQuery.ajax({ type: "POST",
url: serviceURL + "question.php",
data: 'id='+id+'&reply='+reply,
cache: false,
success: AskQuestion});
} else {
window.location = "page.html";
}
}
function UpdateRecord(update_id)
{
var id = getUrlVars()["id"];
jQuery.ajax({ type: "POST",
url: serviceURL + "update.php",
data: 'id='+id,
cache: false,
success: AskQuestion});
}