Answer the question
In order to leave comments, you need to log in
How to send data in dle via javascript post request?
I'm cutting liveeditor https://vitalets.github.io/x-editable/docs.html to the site, while I'm testing there is a field in userinfo.tpl
, in our case username
Full name: {fullname}
how to save data through a javascript post request. Preferably without refreshing the page.
Demo and code codepen.io/litemax/pen/vLgGpm
Answer the question
In order to leave comments, you need to log in
You send everything AJAX to a PHP file, and there you already process and write to the database.
Here is an example from the official documentation:
$('#save-btn').click(function() {
$('.myeditable').editable('submit', {
url: '/newuser',
ajaxOptions: {
dataType: 'json' //assuming json response
},
success: function(data, config) {
if(data && data.id) { //record created, response like {"id": 2}
//set pk
$(this).editable('option', 'pk', data.id);
//remove unsaved class
$(this).removeClass('editable-unsaved');
//show messages
var msg = 'New user created! Now editables submit individually.';
$('#msg').addClass('alert-success').removeClass('alert-error').html(msg).show();
$('#save-btn').hide();
$(this).off('save.newuser');
} else if(data && data.errors){
//server-side validation error, response like {"errors": {"username": "username already exist"} }
config.error.call(this, data.errors);
}
},
error: function(errors) {
var msg = '';
if(errors && errors.responseText) { //ajax error, errors = xhr object
msg = errors.responseText;
} else { //validation error (client-side or server-side)
$.each(errors, function(k, v) { msg += k+": "+v+"<br>"; });
}
$('#msg').removeClass('alert-success').addClass('alert-error').html(msg).show();
}
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question