MoOx / pjax

Easily enable fast Ajax navigation on any website (using pushState + xhr)
MIT License
1.43k stars 124 forks source link

Cannot read property 'match' of null #187

Closed Juliangzr closed 5 years ago

Juliangzr commented 5 years ago

Hello, Im trying to use this script with ASP.NET MVC 5. I enabled the debug, and when i click on a link it throws me this error:

pjax.js:878 GET http://localhost:25282/Clientes/Listar/1?t=1543502398672 500 (Internal Server Error) module.exports @ pjax.js:878 loadUrl @ pjax.js:162 linkAction @ pjax.js:646 (anonymous) @ pjax.js:684 pjax.js:113 Uncaught TypeError: Cannot read property 'match' of null at Pjax.loadContent (pjax.js:113) at Pjax.module.exports [as handleResponse] (pjax.js:749) at XMLHttpRequest.request.onreadystatechange (pjax.js:823) loadContent @ pjax.js:113 module.exports @ pjax.js:749 request.onreadystatechange @ pjax.js:823 XMLHttpRequest.send (async) module.exports @ pjax.js:878 loadUrl @ pjax.js:162 linkAction @ pjax.js:646 (anonymous) @ pjax.js:684

Here is my script

If i enter manually (through browser) to http://localhost:25282/Clientes/Listar/1?t=1543502398672 there is no problem. Anyway, there is no possibility to remove the query string t in the requests ?

Thanks

BehindTheMath commented 5 years ago

In Pjax initialization options, set cacheBust to false. See here.

Juliangzr commented 5 years ago

In Pjax initialization options, set cacheBust to false. See here.

Thank you @BehindTheMath! i setted to false, but im still getting the error.

Juliangzr commented 5 years ago

i solved editing the .js of the loadcontent function: i added the if (html != undefined) {

     if (html != undefined) {
        var matches = html.match(htmlRegex)
        if (matches && matches.length) {
          matches = matches[0].match(htmlAttribsRegex)
          if (matches.length) {
            matches.shift()
            matches.forEach(function(htmlAttrib) {
              var attr = htmlAttrib.trim().split("=")
              if (attr.length === 1) {
                tmpEl.documentElement.setAttribute(attr[0], true)
              }
              else {
                tmpEl.documentElement.setAttribute(attr[0], attr[1].slice(1, -1))
              }
            })
          }
        }
    }
BehindTheMath commented 5 years ago

We should check here if responseText is falsy.