Pjax.prototype.loadUrl() not working #8

Closed
opened 2014-05-16 17:44:51 -05:00 by jfizz · 3 comments
jfizz commented 2014-05-16 17:44:51 -05:00 (Migrated from github.com)

Thanks for this great project!

I am attempting to implement a PJAX redirect with Pjax.prototype.loadUrl(). The actual code is

options = {
        elements: ['a', '.pjax'],
        selectors: ["#pjax"]
};
Pjax.prototype.loadUrl('/', options);

When I attempt to run call this, I get an error

TypeError: Cannot read property 'debug' of undefined
    at Object.Pjax.log (http://localhost:9000/bower_components/pjax/src/pjax.js:213:25)
    at Object.Pjax.loadUrl (http://localhost:9000/bower_components/pjax/src/pjax.js:408:12)
    at Scope.$scope.processForm (http://localhost:9000/scripts/controllers/getStartedController.js:11:22)
    at http://localhost:9000/bower_components/angular/angular.js:10567:21
    at http://localhost:9000/bower_components/angular/angular.js:18627:17
    at Scope.$eval (http://localhost:9000/bower_components/angular/angular.js:12412:28)
    at Scope.$apply (http://localhost:9000/bower_components/angular/angular.js:12510:23)
    at HTMLFormElement.<anonymous> (http://localhost:9000/bower_components/angular/angular.js:18626:21)
    at HTMLFormElement.jQuery.event.dispatch (http://localhost:9000/bower_components/jquery/dist/jquery.js:4409:9)
    at HTMLFormElement.elemData.handle (http://localhost:9000/bower_components/jquery/dist/jquery.js:4095:28) angular.js:9778
(anonymous function) angular.js:9778
(anonymous function) angular.js:7216
Scope.$apply angular.js:12512
(anonymous function) angular.js:18626
jQuery.event.dispatch jquery.js:4409
elemData.handle jquery.js:4095

I fixed this error by adding this.options = options to the very beginning of the loadUrl() function. However, after I fixed that error, I got a new error:

Pjax switch fail:  
TypeError {stack: (...), message: "Cannot read property '#pjax' of undefined"}
 pjax.js:432
(anonymous function) pjax.js:432
request.onreadystatechange pjax.js:395

So with this second error, it falls back to the window.location() option, which is not the behavior that I am looking for. I have messed around with the code in order to fix this error but I have yet to find a solution.

Thanks for this great project! I am attempting to implement a PJAX redirect with `Pjax.prototype.loadUrl()`. The actual code is ``` options = { elements: ['a', '.pjax'], selectors: ["#pjax"] }; Pjax.prototype.loadUrl('/', options); ``` When I attempt to run call this, I get an error ``` TypeError: Cannot read property 'debug' of undefined at Object.Pjax.log (http://localhost:9000/bower_components/pjax/src/pjax.js:213:25) at Object.Pjax.loadUrl (http://localhost:9000/bower_components/pjax/src/pjax.js:408:12) at Scope.$scope.processForm (http://localhost:9000/scripts/controllers/getStartedController.js:11:22) at http://localhost:9000/bower_components/angular/angular.js:10567:21 at http://localhost:9000/bower_components/angular/angular.js:18627:17 at Scope.$eval (http://localhost:9000/bower_components/angular/angular.js:12412:28) at Scope.$apply (http://localhost:9000/bower_components/angular/angular.js:12510:23) at HTMLFormElement.<anonymous> (http://localhost:9000/bower_components/angular/angular.js:18626:21) at HTMLFormElement.jQuery.event.dispatch (http://localhost:9000/bower_components/jquery/dist/jquery.js:4409:9) at HTMLFormElement.elemData.handle (http://localhost:9000/bower_components/jquery/dist/jquery.js:4095:28) angular.js:9778 (anonymous function) angular.js:9778 (anonymous function) angular.js:7216 Scope.$apply angular.js:12512 (anonymous function) angular.js:18626 jQuery.event.dispatch jquery.js:4409 elemData.handle jquery.js:4095 ``` I fixed this error by adding `this.options = options` to the very beginning of the `loadUrl()` function. However, after I fixed that error, I got a new error: ``` Pjax switch fail: TypeError {stack: (...), message: "Cannot read property '#pjax' of undefined"} pjax.js:432 (anonymous function) pjax.js:432 request.onreadystatechange pjax.js:395 ``` So with this second error, it falls back to the `window.location()` option, which is not the behavior that I am looking for. I have messed around with the code in order to fix this error but I have yet to find a solution.
MoOx commented 2014-05-17 07:53:41 -05:00 (Migrated from github.com)

Oh.
You should use a Pjax instance. Not directly the prototype. Maybe you need to learn a little more JavaScript https://encrypted.google.com/search?hl=en&q=javascript%20prototype

See https://github.com/MoOx/pjax#new-pjax

var mypjax = new Pjax({
        elements: ['a', '.pjax'],
        selectors: ["#pjax"]
})

After this you can eventually try (but I'm not sure this will work)

mypjax.loadUrl("/");
Oh. You should use a Pjax instance. Not directly the prototype. Maybe you need to learn a little more JavaScript https://encrypted.google.com/search?hl=en&q=javascript%20prototype See https://github.com/MoOx/pjax#new-pjax ``` js var mypjax = new Pjax({ elements: ['a', '.pjax'], selectors: ["#pjax"] }) ``` After this you can eventually try (but I'm not sure this will work) ``` js mypjax.loadUrl("/"); ```
studioraygun commented 2014-08-01 06:58:03 -05:00 (Migrated from github.com)

Having the same issue, would be much better if the guide could cover this a bit. As it stands, I cannot get Pjax working at all using the readme document.

Having the same issue, would be much better if the guide could cover this a bit. As it stands, I cannot get Pjax working at all using the readme document.
MoOx commented 2014-08-01 06:59:46 -05:00 (Migrated from github.com)

Please provide more informations so I can eventually help you. What code are you using ?

Please provide more informations so I can eventually help you. What code are you using ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: iLoveElysia/pjax#8