Wordpress Create Category AJAX Response

2019-07-03 03:09发布

I currently have a plugin that allows a user to activate/deactivate categories to drive a menu. I've created an option for the toggle and have it functioning in the create form and edit form seamlessly. The only place I can't seem to add it is to the AJAX return from wordpress when the category is created. I can create the column when the Categories page is loaded but don't know how to tap into the AJAX Return without modifying the core. Is there a hook that I'm unaware of that allows you to modify this return?

2条回答
Ridiculous、
2楼-- · 2019-07-03 03:21

Using Akmal's answer, this is my script to check if the Taxonomy-Category was created or not. Thanks Akmal.

Wordpress version 3.8.2

        $(document).ajaxComplete(function(event, xhr, settings) {
            var queryStringArr = settings.data.split('&');
                if( $.inArray('action=add-tag', queryStringArr) !== -1){
                    var xml = xhr.responseXML;
                    $response = $(xml).find('term_id').text();
                    if($response!=""){
                        console.log('This is the action.');

                    }
                }
        });
查看更多
地球回转人心会变
3楼-- · 2019-07-03 03:46

Do you try to run some Javascript after ajax return (after add new category)?

Try to put below code in your code when you create the custom field in category form :

       $(document).ajaxComplete(function(event, xhr, settings) {

         var queryStringArr = settings.data.split('&');

         if ($.inArray('action=add-tag', queryStringArr) !== -1){
             your_javascript_function(); //this is your js function
         }

       });
查看更多
登录 后发表回答