Tuesday, June 7, 2022
HomeWordPress Developmentajax - Why is the file not importing to the server?

ajax – Why is the file not importing to the server?


On wordpress web page i’m utilizing inline vue, as a result of kind is just too advanced.

let formData = new FormData();
formData.append("motion", "topcare");
formData.append("nonce", true_object.nonce);
formData.append("administration_desc", this.controls.administration_desc);
formData.append("administrator_file", this.controls.fileList[0]);

fetch(url, {
        methodology: 'POST',
        physique: formData,
    })
    .then(res => res.json())
    .then(res => {
        this.formSuccess = true;
        this.formWasSent = true;
        this.loading = false;
        console.log(JSON.stringify(res, null, 4));
        setTimeout(() => {
            this.formSuccess = false;
        }, 2000)
    }).catch(error => {
        this.formSuccess = false;
        this.formWasSent = true;
        this.loading = false;
        console.log(JSON.stringify(error, null, 4));
    })

As i understood, i needn’t set Conte-type: multipart-form-data in fetch, as a result of will probably be set automaticaly.

Server php file:

<?php
operate true_localize_example()
{
    wp_enqueue_script('truescript', get_template_directory_uri() . '/vue/topcare/ajax.js', [], null, false);
    wp_localize_script('truescript', 'true_object', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce'    => wp_create_nonce('feedback-nonce'),
    ));
}
add_action('wp_enqueue_scripts', 'true_localize_example');
add_action('wp_ajax_topcare', 'ajax_form');
add_action('wp_ajax_nopriv_topcare', 'ajax_form');
operate ajax_form()
{
    if (!wp_verify_nonce($_POST['nonce'], 'feedback-nonce')) {
        wp_die('Information was recieved from one other tackle');
    }
    if (!empty($_POST['checkField'])) {
        wp_die('It is a spam');
    }

    die(json_encode(array('kind' => 'information', 'textual content' => $_FILES))
    

And $_FILES is empty.
Why?

Thanks prematurely.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments