Friday, October 21, 2022
HomeWordPress Development$wpdb Ajax not redirecting to predominant web page

$wpdb Ajax not redirecting to predominant web page


I am having problem with redirecting a web page as soon as an individual submits information. I made a type, and when the person clicks ‘Add pupil’, the info can be encoded via json, saved within the database. The web page can be can be redirected and refreshed by a customized jQuery class, which refers to a clean div with a category referred to as “messageDiv” (first line of code dispayed beneath.

Nonetheless, when a person submits information, they’re taken a clean white web page with the json string echoing successful or failure upon submission. I am undecided why the web page will not be being redirected appropriately, and why it takes the person to a clean json web page.

How the success message is meant to be displayed:

<div class="messageDiv"></div>

My ajax code:

jQuery(operate() 
    {
        jQuery("#myForm").submit(operate(occasion) 
        {
            occasion.preventDefault();
        
        // ajax operate
        jQuery.ajax
            ({
                dataType: "json",
                kind: "publish",
                information: jQuery("#myForm").serialize(),
                url: "../admin-ajax.php",
                success:operate(information) 
                {
                
                    jQuery(".messageDiv").html(information.message);
                    
                    if(information.standing == 1)
                    {
                        jQuery("#myForm").set off('reset');
                    }
                },

            });
        });
        
    });

The backend database question and connection:

if(isset($_POST['BtnSubmit']))
{
    world $wpdb;
    
    $data_array = array(
        'first_name' => $_POST['first_name'],
        'last_name' => $_POST['last_name']
        );
        
        $table_name="college students";
        
        $rowResult = $wpdb->insert($table_name, $data_array, $format=NULL);
        
        
        if($rowResult == 1) 
        {        
            echo json_encode(array('message' => '<h1>Type added into the database<h1>', 'standing' => 1));
        } else 
        {
            echo json_encode(array('message' => '<h1>Error Type submission<h1>', 'standing' => 0));
        }
        
        die();
} 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments