Ajax Call, Button in a Panel
Question
I'm tryng to do an ajax call for a button inside the panel this is my code:
// Add devices buttons
const panelDevices = pn.addPanel({id: 'loggedas'});
panelDevices.get('buttons').add([
{
id: 'save',
className: 'fa fa-save icon-undo',
text:'A',
run: function(editor,sender)
{
if(sender) sender.set('active',false);
},
command: function(editor,sender)
{
if(sender) sender.set('active',false);
if (confirm("Are you sure??") == true) {
var htmldata = editor.getHtml();
var cssdata = editor.getCss();
var pagetosave = "<head> <style>" + cssdata + "</style> </head> <body>" + htmldata + "</body>";
alert(pagetosave);
$.ajax({
url: "../php.php",
type: "POST",
async: false ,
contentType: "text/html",
data: data,
success: function(res){
alert(res);
},
error: function(res){
alert(res);
}
});
} else {
x = "You pressed Cancel!";
}},
attributes: { title:'Save'}
}
]);
of course i hosted it on a web, but i dont recive response(error or succes) and i tryed an hello world inside the php, but i think the request never started.
Answers (3)
Please read about Panels API addButton() and Command API add()
I think the request never started
You shouldn't think, you have to use devtools to debug
my bad, i used FDE with the console, i just forgot to include jquery.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #436
RemoteStorage - Load Template uses POST
I'm using a custom module to save/load a template with a service like this: Save is a different module and works just fine. The problem is...
Issue #1210
[Question] Replace Devices icon ASP.net / Javascript
Bonjour, I want replace icon for selected devices like in preset-webpage but i don't understand why this code doesn't work and nothing appe...
Issue #1211
Adding a working Import Panel Button without the presets
I want to add the Import button at the panel for importing templates, but I don't want to use the presets. I have already added the followi...
Issue #1258
Style is not copying after cloning the element after Save
Hi @artf. At the first time before saving the template, When I make one element and clone it, the style is coming in the clonned element. T...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.