Jquery Ajax in wordpress without using wp-load.php file in post page

I am using Jquery to post values and get some return values from outside page in my plugin, in that page I am using wp-load.php to access wordpress functionalities. without wp-load.php using in that page how can we get results,
here my code of two plugin pages.

Main plugin file having Jquery.

Read More
var locations = function () {
    var tmp = null;
        $.ajax({        
        'async': false, 
        'type': "POST",
        dataType: 'json',
        url: "<?php  echo plugins_url( 'json.php', __FILE__  ); ?>",
        data: "post_type="+post_type_loc,
            success: function(data){
                 tmp = data;
            }
        });
           return tmp;
    }();

and Json page having code like this.

<?php
// PHP array
include_once("../../../wp-load.php");
?>
<?php 
$products = array();
$post_type=$_POST['post_type'];
$loop = get_posts('post_type='.$post_type); ?>
<?php foreach ( $loop as $post ) : setup_postdata( $post ); ?>


 <?php endforeach;
wp_reset_postdata();
?>

Is there any other way without using jquery ajax and wp-load.php include to do this.

Related posts