开发者

Wordpress Ajax in plugins

Im porting a plugin for Wordpress from a script, and Im find开发者_StackOverflow社区ing it very difficult to update my settings through ajax, or add new options..

I want to use ajax since my original script uses ajax.

What is the best way to approach this?

I have already read through Ajax In Plugins and all of its resources..

Here is the main structure of the plugin

myplugin/js/custom.js <- This has all the ajax requests using jQuery-Ajax myplugin/ajax/ <- in here are all the php files that recieve the settings to be updated. myplugin/plugin.php <- This loads the javascript file.

The javascript is loaded using :

wp_register_script( 'custom_script', plugins_url('/js/custom.js', __FILE__) );
wp_enqueue_script( 'custom_script' );

Any help is greately appreciated..


Ok it took me some time to realize how the whole thing works, but here is the deal:

You use the following example code:

Javascript
$.ajax({ type: "POST", url: "admin-ajax.php", data: {action: "DoMyAjaxStuff"} success: function(){ } });

PHP

add_action('wp_ajax_DoMyAjaxStuff', 'myajaxfunc');

function myajaxfunc{
//Do stuff here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜