Ajax post is not working after wordpress integration in laravel

Ajax post is working fine before I integrate wordpress in my project. After the wordpress integration its shows a 404 error. But when try to debug using firebug we can see that the response is correct.

WordPress integration code,

Read More
require  "..".DIRECTORY_SEPARATOR ."public". DIRECTORY_SEPARATOR . 'blog'. DIRECTORY_SEPARATOR . 'wp-blog-header.php';

Ajax code,

var token = "{{csrf_token()}}";
$.ajax({
    method: "POST",
    url: "{{URL::to('ajax/country/load_cities')}}",
    data: {  '_token':token, 'country_id': 12 } 
}).done(function(data) {
   console.log(data);
});

Controller function,

public function loadCountryCities(){
    echo "response";
    exit;
}

routes.php,

Route::post('ajax/country/load_cities', array('as' => 'countryloadcities','uses' => 'CitiesController@loadCountryCities'));

The code working fine when remove the require statement. How can we make works the post response too ?

Related posts

1 comment

  1. You need to include wp-config.php instead of wp-blog-header.php.

    wp-blog-header.php is used to include the WordPress Core + the post functionalities in order to display a template. Considering you don’t send a valid post url this is probably why it was breaking. Instead, wp-config.php is including the WP core only and can be used in any external file to work with WP functions.

Comments are closed.