I'm trying to alter the registration procedure that WordPress is using by adding another 'step.'
Since I added foreign key constraints in my database tables, wp_users need to be filled first and after executing the rest of the code.
My current code for WordPress form submit interruption is:
jQuery("#registerform").submit(function (e){
e.preventDefault();
let self = jQuery(this);
self.unbind().submit();
setTimeout(function(){
if (jQuery("#registerusingwebauthn").is(":checked")) {
let username = jQuery("#user_login").val();
initializeCredentialType({
authenticationMethod: "webauthn"
});
webauthn_registration(username,null)
.then(function(e){
alert(e);})
.catch(function (e){
console.log(e)});
}
},60000);
});
The self.unbind().submit(); part it's used because the wp_users table must be filled in first, or else a violation of constraints will occur.
The webauthn_registration is returning a new Promise and it's defined as follows:
const webauthn_registration=(username,type)=>{
return new Promise((resolve,reject)=>{
// some variable definition here//
if (username === ""){
reject("Error: Username not given");
}
$.ajax({
url: url,
type: 'GET',
data: {'username': username},
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (error){reject(error);},
success: function(serverregdata){
// some variable definition here//
navigator.credentials.create({publicKey: serverregdata})
.then(function(credentials){
// some variable definition here//
$.ajax({
url: url,
type: 'POST',
data: JSON.stringify(credentials),
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (error){alert(error);reject(error);},
success:function(success){alert(success);resolve('success');}
})
});
}
});
});
}
The problem is that setTimeout() doesn't wait until the promise that webauthn_registration is resolved and reloads the page before webauthn_registration is finished.
For some more information (if needed), AJAX is interacting with a python server, and the Tables Constraints are as follow:
wp_users.username is a foreign key to webauthn_users.
webauthn_users.id is a foreign key to webauthn_credentials.
PS
The webauthn_registration function was working fine in a static HTML website that the submit function was directly linked to webauthn_registration.
Welcome to stackoverflow. I would suggest to try the following trick:
$('form').one('submit', function(e) {
e.preventDefault();
// do your things ...
// and when you done:
$(this).submit();
});
Related
$(document).ready(function () {
$.ajax({
url: "/file_lines",
type: 'GET',
// contentType: 'application/json', // format of Data to be sent to the server
// data: 'json',//Data to be sent to the server
dataType: 'text', //The type of data that you're expecting back from the server.
success: function (lines) {
document.getElementById("tmp").innerHTML = lines
**console.log(document.getElementById("tmp").innerHTML)**
},
error: function (){
alert("get debug log's lines failed");
return false;
}
});
})
// console.log($('#tmp').html())
**var num = document.getElementById("tmp").innerHTML
console.log(num)**
I am so confuse that why I can get innerHtml value of "tmp" in the $(document).ready() but can not get this value outside $(document).ready()! I thought DOM object should be global. So I am quite confuse about this result. Could somebody help me?
I'm trying to send multiple data from client to server using ajax json.
case First: when i send my form inputs data from client to server it was going well.
case second:now one modification done in my form and i am generating dynamic multiple rows with textboxes .and it's values should also pass using same ajax method but my try go in vain so any idea would be appreciated.
Refer below article for more coding part details about this question.
enter link description here
I am trying like this
$(document).on("click", "[id*=btnFrmSubmit]", function () {
alert("hi");
var fields = $("#WireDimTbl tbody").find(":input").serializeArray();
var user = {};
user.PRODUCT_ID = 1;
user.TDC_NO = $("[id*=Tdc_No]").val();
user.REVISION = $("#Revision").text();
$.ajax({
type: "POST",
url: "TDC.aspx/SaveFrmDetails",
data: JSON.stringify({ user: user,fields:fields}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("Data has been added successfully.");
window.location.reload();
},
error: function (response) { alert(response.responseText); }
});
return false;
});
At Sever side part what modification should be done.how would i define parameter object with same strucutre at server side and how would i store in db.
I have an Ajax call being made from a button press which returns me some data then goes off and creates a grid. The first time the function is called the Ajax call is made, data is returned and the grid is displayed. Happy Days.
However any subsequent call to the function, where none of the data parameters are changed, result in the Ajax call not being made to the server and the function skips straight to 'success' with the results from the successful call already populated.
Changing any of the 'postParameters' results in a successful Ajax call and the data is refreshed.
function btnClick(){
//blah blah
getGridData();
}
function getGridData() {
var postParameters =
{
SiteID: "#Model.SiteID",
DateFilterFrom: $("#datepickerFrom").val(),
DateFilterTo: $("#datepickerTo").val(),
CustomerFilter: $("#customers").val()
};
$.ajax({
url: "#Url.Action("SalesForecast_Read", "Planning")",
type: "GET",
contentType: "application/json; charset=utf-8",
data: postParameters,
dataType: "json",
success: function (results) {
createHighlights(results.Highlights);
createGrid(results.Entries);
},
error: function (e) {
alert(e.responseText);
}
});
};
I know there must be an important Javascript concept I am missing but I just cant seem to be able to nail it.
Can anyone help put me in the right direction?
Have you tried to disable the cache with:
$.ajax({
url: "#Url.Action("SalesForecast_Read", "Planning")",
type: "GET",
cache: false,
contentType: "application/json; charset=utf-8",
data: postParameters,
dataType: "json",
success: function (results) {
createHighlights(results.Highlights);
createGrid(results.Entries);
},
error: function (e) {
alert(e.responseText);
}
});
Explanations
The cache basically tries to save a call to the server by saving the return value of the calls.
It saves them using a hash of your query as a key, so if you make a second query that is identical, it will directly return the value from the cache, which is the value that was returned the first time.
If you disable it, it will ask the server for every query.
You can add cache: false to your ajax request.
$.ajax({
url: "#Url.Action("SalesForecast_Read", "Planning")",
type: "GET",
contentType: "application/json; charset=utf-8",
data: postParameters,
dataType: "json",
cache:false,
success: function (results) {
createHighlights(results.Highlights);
createGrid(results.Entries);
},
error: function (e) {
alert(e.responseText);
}
});
IE might not listen to you though. For that you can add a field to the POST Parameters, where you add the current time in miliseconds, so even IE does not cache.
try to add this in ur ajax call:
$.ajax({
cache: false,
//other options...
});
This will force the recall of the ajax each time.
For more information please check the following link :
api.jquery.com/jquery.ajax
i have a list of records and on each record, if I click I go to a different page.
On the 2nd page, i change the status of the record. I change the status on changing a value in the dropdown. when I change the value in the dropdown, i call an api to commit the change.
after the success call I am redirecting users to the list page where records should have changed status value.
this works in all browser but NOT IN I.E (Not even in i.e. 11)
In I.E, when i go to the list page I see the old value untill I press f5 and refresh.
the following code is running when I change the status of my record in the 2nd page.
function changeStatus(status)
{
$.ajax({
type: "GET",
url: "api call url",
dataType: "xml",
async: false,
success: function (data) {
// alert("success call");
window.location = "list url"; // adding a datetime() here, doesn't give me any luck.
},
error: function () {
alert("Error");
}
});
}
i tried many things, including putting a datetime in the url with no luck.
is there any workaround?
You can make use of the cache setting (jQuery reference)
function changeStatus(status)
{
$.ajax({
type: "GET",
url: "api call url",
dataType: "xml",
async: false,
cache: false,
success: function (data) {
// alert("success call");
document.location = "list url"; // adding a datetime() here, doesn't give me any luck.
},
error: function () {
alert("Error");
}
});
}
I am trying to build a log in application in PhoneGap. Ive been looking around a lot for similar things and I found them plenty... but I do not understand why this pieces of code does not work. When i press the logIn_btn it shows that It cannot reach the "success" piece of code. Thank you for your help!
$('#logIn_btn').click(function(){
user = $('#username').val();
pass = $('#password').val();
var ev = {'papa':true};
if(user!='' && pass!=''){
alert('trying login');
$.ajax({
url: 'https://localhost/server/IF/mobileApp/login.php',
type: 'post',
datatype: 'json',
data: ev,
success: function(data){
alert('asd');
}
});
console.line('done.')
} else {
alert('Please insert your username and password.');
}
});
Your server should not be https://localhost, it should be the name/ip of the server that you'll be logging into.
For additional information, look at your network tab with Chrome, or install a fail handler
$.ajax({
url: 'https://localhost/server/IF/mobileApp/login.php',
type: 'post',
datatype: 'json',
data: ev,
success: function(data){
alert('asd');
}
}).fail(function(jqXHR, textStatus){
});
console.line?I think it would be console.log. Rather try alerting the message. Also make sure the javascript executes after deviceready. Also localhost in android is a very different thing. Try using the ipadress or domain name to access the server.