简体   繁体   中英

Laravel 5.1 Call PHP file on Javascript string

How to call some PHP file in Laravel 5.1.

I have to see of that PHP file echo.

Here is the Javascript codes

<script>
$(document).ready(function(){
    $('#example').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": 'processing.php'
    });
});
</script>

Hope you can write a route controller for that php file and call the route method in Javascript.

For example, Destination file: processing.php

Create a Route like this.

Route:get('processing', ['as=>'processing', 'uses'=>'ProcessingController@index']);

create a new controller with name ProcessingController.php,

[to create a controller in command : php artisan make:controller ProcessingController]

Inside the file add the business logic in index().

Now you can call the

<script>
$(document).ready(function(){
  var processing = '<?php echo URL::route('processing') ?>';
    $('#example').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": processing
    });
});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM