defunkt / jquery-pjax

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

if i use WordPress, that i get error - wordpress jquery-pjax (jquery.pjax.js:672) #683

Open Yuriy-Svetlov opened 7 years ago

Yuriy-Svetlov commented 7 years ago

if i use WordPress, that i get error - wordpress jquery-pjax (jquery.pjax.js:672) if i use on yii2 or .html static websites that they working is good

$body = undefined in the code

$body = $(parseHTML(data.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0]))

jquery-3.2.1.min.js

log errors

Uncaught TypeError: Cannot read property '0' of null
    at extractContainer (jquery.pjax.js:672)
    at r.fn.init.options.success (jquery.pjax.js:262)
    at i (jquery-3.2.1.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-3.2.1.min.js:2)
    at A (jquery-3.2.1.min.js:4)
    at XMLHttpRequest.<anonymous> (jquery-3.2.1.min.js:4)

$(document).pjax('a', '#pjax-container', {fragment: '#pjax-container', container:'#pjax-container', timeout: 30000, push: true});

eteka75 commented 4 years ago

I have same Error Uncaught TypeError: Cannot read property '0' of null at extractContainer (pjax.js:671) at n.fn.init.options.success (pjax.js:262) at i (jquery-1.12.4.min.js:2) at Object.fireWith [as resolveWith] (jquery-1.12.4.min.js:2) at y (jquery-1.12.4.min.js:4) at XMLHttpRequest.c (jquery-1.12.4.min.js:4)

devOp commented 2 years ago

https://github.com/defunkt/jquery-pjax/blob/153262eda33e31119eabb97cd5f14365580a3b35/jquery.pjax.js#L661

I have a pjax response which contains a string containing '\<html>' in a javascript error message. This makes pjax to fail with the same error because pjax is looking for a \<html> tag and then later for body(Line 672) which is not there in my case leading to the error. So maybe its a good idea to include a parameter telling pjax if the response will be a full html document or only a subset and then skip this auto detection.