i want to make a wordpress plugin.
But i want to learn, plugin admin panel how to click and run function.
same page if you click link call function but same page ajax.
like this
<a href='javascript:void(0); class="btn2"'>
function examplefunc() {
echo 'say hello':
}
this is easy example. same page if click btn2 class call examplefunc
How to make this thank you so much.
To call java script function in hyperlink then below is the simple example;
<script type="text/javascript">
function myFunction(myMessage) {
alert(myMessage);
}
</script>
My link
Simple WordPress Ajax Example: https://gist.github.com/devinsays/69a305053e35a10584f94d6011bba2d6
Related
How can I add jQuery code inside magento2 pages? For example I have a "Contact us" page. So I can edit the content inside contact us page by
Login to Admin panel
admin -> content -> Pages -> Contact us
I want to add some jQuery code.
So I write
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
<script>
jQuery(function($){
$(".mybox").on("click", function(){
MY CODE *******
});
});
</script>
Here the problem is: I have to call <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
Otherwise it will not work. How can I solve this?
ie. How can i add jquery code in wysiwig editor
Magento 2 Uses Require js
Try using
<script>
require([
'jquery'
], function ($) {
$(".mybox").on("click", function () {
console.log('your code starts here');
console.log('your code ends here');
});
});
</script>
I'm beginner with drupal, I use drupal 7.x and I would like to create a simple ajax call.
I have a template file and I have a button in it with a javascript function in onclick method.
<input type='button' onclick='doajax()'>
<div id='ajaxresponsediv'></div>
In the js file:
function doajax()
{
jQuery.get(url,function(data) {
jQuery("#ajaxresponsediv").html(data);
});
}
Ok it's a simple thing. But what do I have to code in .module file ? What will be the url variable in my code? How do I implement the callback function (for example I would like to print simply 'Hello' into ajaxresponsediv ) ? Do I have to register something in mymodule_menu() function? Thanks for the guidelines.
Yes, you need to register a menu. Hope the below examples help you.
https://clikfocus.com/blog/simple-ajax-example-for-drupal-6-and-7
https://www.drupal.org/docs/7/api/javascript-api/ajax-in-drupal-using-jquery
I have a ajax function that is called by button tag
<button id="of_save" type="button" class="button-primary">
<?php echo __('Save All Changes', 'optionsframework');?>
</button>
$('#of_save').live('click',function() {
...
...
...
}};
The problem is that theme author put a single button on top of settings page and a million of settings, so every time I want to hit save, I must scroll whole page.
I found a little JS script that intercept CTRL+S or another browser combination and is working wonderful
http://www.openjs.com/scripts/events/keyboard_shortcuts
The problem is I don't know how to call the ajax function from this JS
shortcut.add("Ctrl+Shift+X",function() {
alert("Hi there!");
// not working...
live('click',function());
});
i am making a simple site in php. I have a product page and there is a link on product page that says add to wishlist so when a user clicks on that link the product is posted to the server and the page is redirected from the backend. but I want to do it using jquery ajax so that my page is not reloaded. can somebody please provide a snippet of code on how to do that ?
$('#anchorId').click(function(){
$.ajax({
url:"foo",
data : "the query string",
...
...
success: function(result){
// success code.
}
});
return false; // prevents the default behavior of anchor click.
});
The best way to learn jQuery, is to visit the API site. (Which seems to be down at the moment)
The ajax category
Update:
$('body').on('click', 'a.foo', function(){
// What you want here.
return false;
}
This will catch any click on anchors with the foo class under <body> no matter when they were created("runtime" or with the page load) .
I just started using Ajax with jQuery and PHP. I have a working code (below) which inserts some HTML code to a HTML container (div called nav sub).
Next time I try to run a similar code to the one below on my generated HTML, jQuery don't seem to find it. I guess it don't update it self about it when it's added.
$(".nav.top a").click(function(){
var a_class = $(this).parent().attr("class");
$(".nav.sub").html("loading...");
$(".nav.sub").load("<?php echo get_bloginfo('url'); ?>/?addmod_ajax=1",{button: a_class});
return false;
});
Let's say the generated code looks like this:
<div class="nav sub">
My new generated button, forgotten by jQuery?
</div>
And the new container looks like this:
<div class="settings"><?php # AJAX ?></div>
Is it some way to use jQuery and Ajax on HTML code generated with jQuery?
I figured it out. The solution is to use "live".
$('.nav.top a').live( 'click', function() {
var a_class = $(this).parent().attr("class");
$(".nav.sub").html("loading...");
$(".nav.sub").load("<?php echo get_bloginfo('url'); ?>/?addmod_ajax=1",{button: a_class});
return false;
});