#1 2015-09-14 10:49:27

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Load View files by AJAX Request

I have two pages.
The first page loaded by ionize and it doesn't matter.
then the second page is loaded by ajax but does not appear content.
please help master

Last edited by adaliszk (2015-10-14 21:57:05)

Offline

#2 2015-09-14 11:05:40

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: Load View files by AJAX Request

johanriyan wrote:

I have two pages: The first page loaded by ionize and it doesn't matter.
then the second page is loaded by ajax but does not appear content.

If I understand right:

This is one site with two pages, the first page is loading without ajax and working. The second page is a link and you have some link-ajax handler to load the content? If it so then please share the code which does not working.

Last edited by adaliszk (2015-09-14 11:07:04)


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#3 2015-09-14 13:04:27

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

this is second page but same page.
url: talisman.baseFolder + "themes/jambimerang/views/"+state.data.node_name+".php",
example
page_about.php is loaded using ionize.
ane second page is about.php using ajax like url above.
how to get tag ionize on about.php using ajax or using another query maybe.

please help master.

Last edited by johanriyan (2015-09-14 13:05:21)

Offline

#4 2015-09-14 13:25:03

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

how query tag ionize on about.php?

Offline

#5 2015-09-14 13:31:16

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: Load View files by AJAX Request

First of all Why do you want to load the view file? the view file will not working without the core. Call the page url and get the content from there. On the administration panel you can change the view in the settings panel of the page.

Please use [ code ] bbcode around your code. And I do not know how its work int TweenLite but here is a native javascript solution with XMLHttpRequest:

function ajaxize_links( parent )
{
    if( typeof parent == "undefined" ) parent = "";

    document.querySelector(parent+' a').addEventListener('click', functon()
    {
        var target = this.getAttribute('target');
        var url = this.getAttribute('href');

        if( target != "_blank" && url.indexOf("<ion:base_url />") >= 0 )
        {
            var Ajax = new XMLHttpRequest();
        
           Ajax.onreadystatechange = function()
           {
                if( Ajax.readyState == 4 && Ajax.status == 200 )
                {
                    var parser = new DOMParser();

                    // Parse the response as a Text/HTML
                    var page = parser.parseFromString(Ajax.responseText,"text/html");

                    // Get the new content from an element
                    var content = page.getElementById('id_of_content').innerHTML;

                    // Change the current element to the new
                    document.getElementById('id_of_content').innerHTML = content;
               
                    // Other code...

                    // Dont forget to add event listener to the new content
                    ajaxize_links('#id_of_content');
                }          
           }

            Ajax.open("GET", url, true);
            Ajax.send();
        }
    });
}

ajaxize_links();

Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#6 2015-09-14 13:42:17

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

another solution maybe?
how to tag query on about.php using ionize?

Offline

#7 2015-09-14 13:43:18

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

about.php is loaded, but how to query ionize on about.php?

Offline

#8 2015-09-14 13:49:55

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: Load View files by AJAX Request

You can not load the view file by direct linking to the view file. The code does not know which content do you want to load and the template parser can't replace the elemenets in that way.

You can load the URL of the new content and get the content and put into your HTML DOM. You can detect the ajax request by using the input class of the CodeIgniter and you can hide the unnecesseary code from the output:

<!-- HTML CODE -->

<?php if( $this->input->is_ajax_request() == false ): ?>

<!-- NON AJAX HTML CODE -->

<?php endif; ?>

<!-- HTML CODE -->

Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#9 2015-09-15 12:02:01

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

I don't understand. Can be explained in detail how the process?
page about.php is loaded but cannot appear content.
how to make tag ionize in about.php?

Offline

#10 2015-09-15 12:20:50

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: Load View files by AJAX Request

johanriyan wrote:

I don't understand. Can be explained in detail how the process?
page about.php is loaded but cannot appear content.
how to make tag ionize in about.php?

As a PHP Application Ionize gather the Apache request and depend on the parameters reacting that. Every request must trought a bootstrap php which is the index.php in the root folder. This index.php will load the Codeigniter framework and the Ionize CMS. The Ionize after that load getting the data from the database based on URL and that Ionize will load and parse the view file and the output will be sent as a response.

If you want load just data from the database you should make a module for that or a view which does not load the html markup. If you want load a view file into the current page you must request the wanted url and get the elements from the response. You can set the view file on the adminisration panel, if you want a dinamic view you can handle it in the view file.


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#11 2015-09-15 12:24:22

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

example please?
if using ajax and how to make query tag ionize in view?

Offline

#12 2015-09-15 12:31:39

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: Load View files by AJAX Request

johanriyan wrote:

example please?
if using ajax and how to make query tag ionize in view?

What do you want exactly? I do not know what do you mean with "query tag ionize in view"?


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#13 2015-09-15 12:42:28

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

i confuse. how to make ajax on view.
i'm sorry adam.
hot to make query codeigniter in view like your example

<?php if( $this->input->is_ajax_request() == false ): ?>

because i got error.

Last edited by johanriyan (2015-09-15 12:43:32)

Offline

#14 2015-09-15 12:46:05

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: Load View files by AJAX Request

What is the error?


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#15 2015-09-15 12:57:19

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

<b>Fatal error</b>:  Using $this when not in object context in

Offline

#16 2015-09-15 12:59:41

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

i'm using that logic same page, page_about.php loaded using ajax and direct. but same cannot appear when i'm using ajax tag ionize cannot function.

<?php
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') { ?>

Last edited by johanriyan (2015-09-15 13:00:14)

Offline

#17 2015-09-15 13:14:57

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: Load View files by AJAX Request

But you cannot load a view file by direct loading it!! The first one is loaded by the SYSTEM the second one is loaded as a standalone script. It has no object context and no variables in it.

ONLY WAY TO LOAD THE OTHER PAGE BY AJAX IS LOADING THE URL.

The view file will be processed by the SYSTEM and show on the output.
On the administration you must set the second page view by

editing the page > show options > select view on the sidebar

If the view is not in the select then go to the Theme settings and add a name and set as a page view.

Last edited by adaliszk (2015-09-15 13:15:10)


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#18 2015-09-15 13:41:58

johanriyan
Member
Registered: 2015-09-14
Posts: 17

Re: Load View files by AJAX Request

how to make standalone script?

Offline

#19 2015-09-18 15:29:57

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: Load View files by AJAX Request

I wrote a complete solution for you problem, if you can't understand please ask. The way you wanted use the views is not the proper way in php. In fact MVC stcture cant handle that you described to want.


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel, Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Ionize Translations