• i am newbie in wordpress. i have just started with wordpress before some day.

    i am doing here ajax request to contact.php file. everything is working fine. but i am facing problem is when i am including wp-load.php the json data is not coming/printing.

    if i am not including wp-load.php then JSON data is coming/printing. i don’t what’s going wrong with my file if i am including wp-load.php file.

    myscript file

    var name=$("#firstname").val();
               var email=$("#useremail").val();
               var contact=$("#mobile").val();
               var type=$("#type").val();
               var msg=$("#message").val();
               var data = { 'name': name, 'email' : email, 'contact' : contact, 'type' : type, 'msg' : msg };
               $.ajax({
                   url : '/theme_demo/wp-content/themes/bootstrap/contact.php',
                   type : 'POST',
                   data : {result:JSON.stringify(data)},
                   success : function (msg)
                   {
                      alert(msg);
                   }
               })

    contact.php

    <?php
     require_once('../../../wp-load.php' );
    
     if(isset($_POST['result']))
     {
       global $wpdb;
       $data= $_POST['result'];
       $data = json_decode($result,true);
    
        echo $data['name'];
     }
    ?>

    here if i won’t include this require_once(‘../../../wp-load.php’ ); then it’s working but i am including it then json is not responding.

    i want to include require_once(‘../../../wp-load.php’ ); it because i am interacting with database so..

    can you suggest me what am i doing wrong in my code?

    Thanks in advance..

  • The topic ‘Json code is not working when i am including wp-load.php in my file’ is closed to new replies.