MoOx / pjax

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

loadUrl() not change url and some error #152

Closed hanzzame closed 6 years ago

hanzzame commented 6 years ago

i have a problem using loadurl() if i use pjax.loadUrl("/your-url"); i have a error typeError: options is undefined on line 154:5 pjax.js this my script

(function ($) {
    'use strict';
    var pjax = new Pjax({
            elements: [".ajax-nav a"],
            cacheBust : false,
            history : true,
            currentUrlFullReload : false,
            selectors: ["header,title,.app,.ajax-footer,.ajax-nav"]
        })
        window.activenav = function () 
        {
        $(".ajax-nav a").each(function () {
                if (this.href == window.location.href) {
                    $(this).addClass("active");
                    $(this).parent().addClass("active"); // add active to li of the current link
                    $(this).parent().parent().prev().addClass("active"); // add active class to an anchor
                    $(this).parent().parent().prev().click(); // click the item to make it drop
                }
        });
      }

        function callFunctionApp() {

          var options = { 
            beforeSubmit:  showRequest,  // pre-submit callback 
            success:       showResponse,  // post-submit callback 
            dataType:  'json',       // 'xml', 'script', or 'json' (expected server response type) 
            //clearForm: true,       // clear all form fields after successful submit 
            //resetForm: true        // reset the form after successful submit 
          };
          function showRequest() { 
              $('body').loading({
                message: 'PROSES...'
              });          
          } 
          function showResponse(response)  { 
              $('body').loading('stop');

                if (response.status === 'error'){
                  var icon = 'ti-close';
                  var title = '<strong>Oops!</strong>';
                } else {
                  var icon = 'ti-check';
                  var title = '<strong>Well done!</strong>';
                }
              $.notify({
                  title: title,
                  icon: icon,
                  message: response.message,
                },{
                  type: response.type,
                  allow_dismiss: false,
                  showProgressbar:true,
                  placement: {
                    from: "top",
                    align: "right"
                  },
                  offset: {
                    x : 20,
                    y : 90
                  },
                  timer: 100,
                  animate: {
                    enter: 'animated fadeInRight',
                    exit: 'animated fadeOutRight'
                  }
                }); 

              pjax.loadUrl(response.url);
          } 

          $('form').on('submit', function(e) {
            e.preventDefault(); // prevent native submit
            $(this).ajaxSubmit(options);
          });

          activenav();  
        }
        callFunctionApp()
        document.addEventListener('pjax:complete', callFunctionApp)
})(jQuery);

if i comment //options.requestOptions.timeout = this.options.timeout inline 154 page is load but url not change.

how to fix this. Thanks.

BehindTheMath commented 6 years ago

This is a duplicate of #127.

This has been fixed and will be released with v0.2.6. Until then, you can use the workaround mentioned in #127.

BehindTheMath commented 6 years ago

Regarding the URL not changing, does the new page load?

hanzzame commented 6 years ago

yes new page is load, only url not change.

BehindTheMath commented 6 years ago

Can you try with the latest version from Github? Clone the repo, and run npm run build.

hanzzame commented 6 years ago

Hallo,

this problem solved thanks for your support i follow instruction in #127 and npm run build

is this can support submit/upload image enctype="multipart/form-data"?

Thanks you.

BehindTheMath commented 6 years ago

this problem solved thanks for your support i follow instruction in #127 and npm run build

Great. We hope to release v0.2.6 soon, which will include this fix.

is this can support submit/upload image enctype="multipart/form-data"?

Right now, no, but it's the next thing on my to do list. See #132.