Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROBLEM Access to files with AJAX
#6
There are many ways to achieve that. The one option would be to call a processor function via Ajax. This function returns you all desired details of your page. The content can be sent and received in the json format, for instance.

First off, the ajax call in your template file:
Code:
var slug = 'your_slug';
$.ajax({
    url: 'http://your-domain.com',
    type: 'GET',
    data: {
        'getPageContent': slug
    },
    dataType: 'json',
    success: function (data) {
        if(data) {
            console.log(data.content);
        }
    }
});

Your controller, a few lines in the functions.php:
PHP Code:
if(!empty($_GET['getPageContent'])) {
    echo 
json_encode(your_function($_GET['getPageContent']));
    exit();


Your processor (could be a function in your functions.php file):
PHP Code:
function your_function($slug) {
    
$data null;
    
$id null;
    
$id lowercase(str_replace('/'''str_replace('..'''$slug)));
    if(
$id) {
        
$data getXml(GSDATAPAGESPATH.$id.'.xml');
    }
    return isset(
$data->content) ? array('content' => (string)$data->content) : null;

Reply


Messages In This Thread
Access to files with AJAX - by lotova - 2017-08-13, 00:01:46
RE: Access to files with AJAX - by shawn_a - 2017-08-13, 00:47:51
RE: Access to files with AJAX - by Bigin - 2017-08-13, 00:59:37
RE: Access to files with AJAX - by lotova - 2017-08-14, 17:01:47
RE: Access to files with AJAX - by shawn_a - 2017-08-13, 01:02:25
RE: Access to files with AJAX - by Bigin - 2017-08-14, 19:20:12
RE: Access to files with AJAX - by roy_b8te - 2017-08-19, 07:19:23
RE: Access to files with AJAX - by Bigin - 2017-08-19, 16:40:31
RE: Access to files with AJAX - by roy_b8te - 2017-08-19, 17:57:03
RE: Access to files with AJAX - by Bigin - 2017-08-19, 18:25:32
RE: Access to files with AJAX - by roy_b8te - 2017-08-20, 20:49:09
RE: Access to files with AJAX - by shawn_a - 2017-08-20, 05:36:18



Users browsing this thread: 1 Guest(s)