defunkt / jquery-pjax

pushState + ajax = pjax
https://pjax.herokuapp.com
MIT License
16.73k stars 1.97k forks source link

PJAX + DOM Hard Load #692

Closed tetrahydra closed 6 years ago

tetrahydra commented 6 years ago

I need to change/filter some contents before that it is being displayed, so I use this DOM method.

$doc_content = new DOMDocument();
$doc_content->loadHTML('<!DOCTYPE html><html><meta http-equiv="content-type" content="text/html; charset=utf-8"><body>' . $content_cms . '</body></html>');

On every page that uses this method PJAX will hard (force) load the page. When I remove this process, PJAX works fine.

Is there any work around for this issue?

staabm commented 6 years ago

Cant you just filter the ajax contents with jquery means?

tetrahydra commented 6 years ago

we have to filter inappropriate word using another database and resize photos or disabled photos from being displayed. jquery will slow down the process as all of the words need to be sent along with the output.

staabm commented 6 years ago

Hmm ok, didnt got what you said intially. Why do you render a document incl. Doctype etc?

tetrahydra commented 6 years ago

I tried like this before:

$doc_content->loadHTML($content_cms);

and this function doesnt work

$imgs = $doc_content->getElementsByTagName('img');

that loadHTML requires html rendering.

staabm commented 6 years ago

I still dont get what you are doing and why. Usually you would just return/render your $cms_content without this javascript loadHtml thing.

Could you provide more information, why you need this additional javascript?

tetrahydra commented 6 years ago

the DOM and loadHTML are PHP code.

  1. Get all non-permitted words from mysql database.

  2. Filter the word from $cms_content.

  3. Return the filtered content.

  4. Get all IMG tags in $cms_content

  5. Check the filename against mysql database

  6. If not-permitted for display, remove the tag.

  7. Return filtered content.

tetrahydra commented 6 years ago

I have it solved.

$content_cms = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', $content_cms);