admin管理员组

文章数量:1125013

I found below code in a Plugin.

const sent_urls = () => {
        const formData = new FormData();
        formData.append('action', 'start_parsing');
        formData.append('of_start_parsing_nonce', of_start_parsing_nonce.value);
        formData.append('urls', urls.slice(offset, offset + limit));
        formData.append( 'category_fans', category_fans );



        fetch(ajaxurl, {
            method: 'POST',
            body: formData
        }).then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.json();
        }).then(data => {
            if (data.error) {
                throw new Error(data.error);
            }

            if (!data.result) {
                throw new Error('Unknown error');
            }

            added += data.result.added;
            exists += data.result.exists;
            error_urls = error_urls.concat(data.result.error);
            offset += limit;
            count_urls.textContent = 'Imported ' + all_urls + ' urls. ' + 'Added ' + added + ' urls. Exists ' + exists + ' urls. ' + 'Error ' + error_urls.length + ' urls.';

            if (offset >= urls.length) {
                enable();

                alert.show_success('Parsing complete. Added ' + added + ' urls. Exists ' + exists + ' urls.');

                if (error_urls.length > 0) {
                    textarea.value = error_urls.join('\n');
                } else {
                    textarea.value = '';
                }

                offset = 0;
                added = 0;
                exists = 0;
                error_urls = [];

                return;
            } else {
                sent_urls();
            }
        }).catch(error => {
            enable();
            alert.show_warn(error);
        });
    }

This code is create a Post.

How this AJAX Form submitted ?

How a new post is created in WordPress ?

本文标签: postsCode understanding