JavaScript Jquery elements not rebinding + HTMLDivElement unrecognized expression jquery bind elements

I am creating a dynamic refresh feature for div elements on my site that need to be dynamically refreshed.

$(document).ready(function() {

        function refreshDiv() {
            var refreshUrl =  window.location.pathname;

            $('.refreshable').each(function() {
                $(this).fadeOut("slow", function() {
                    $(this).hide().load(refreshUrl + " " + this, "").fadeIn("slow");
                });
            });
        }

        $(document.body).on("click", ".login_button.submit", function(e) {
            e.preventDefault();
            var username = $('#username').val();
            var password = $('#password').val();

            $.ajax({
                type : "POST",
                url : '/login',
                data : {username:username, password:password},

                success:function(response) {
                    if(response.status == 'success') {

                        $('#sb-site').animate({'opacity': '1'}, 300);
                        $('#login_form').toggle();
                        refreshDiv();

                    } else {
                        console.log('Something went wrong');
                    }
                },
                error:function(response) { 
                    console.log('Something went wrong');
                }
            });
        });

        $(document.body).on("click", ".logout_button", function(e) {
            e.preventDefault();

            $.ajax({
                type : "POST",
                url : '/logout',

                success:function(response) {

                    if(response.status == 'success') {
                        refreshDiv();
                    } else {
                        console.log('Something went wrong');
                    }

                },
                error:function(response) { 
                    console.log('Something went wrong');
                }
            });
        });
    });

I have a few issues that have come up.

1) After logout is clicked, it calls the Laravel controller at /logout. After that, it loads up the page with the refreshed content, but the jquery click events wont rebind, so I have to refresh in order to log in again after a logout. The elements rebind fine after login happens, however. I figured using .on() would fix this, but it has not.

2) Elements are duplicated because I am having trouble implementing 'this' into the refreshDiv function. I get an error:

Uncaught Error: Syntax error, unrecognized expression: [object HTMLDivElement]

This doesn't happen if I do

$(this).hide().load(refreshUrl + " .refreshable>*", "").fadeIn("slow");

but I need it to reload each specific targeted element individually, or it overlaps the content with matching classes. I tried:

$(this).hide().load(refreshUrl + " " + this, "").fadeIn("slow");

My goal is to just be able to have a scalable solution to just add a .refresh class to a wrapper that needs to be dynamically refreshed.

Answer:1

I'm looking to purge Cloudflare's cache through its API. More specially, the purge all files command. However, I keep running into the "Invalid Content-Type header, valid values are application/json,...

I'm looking to purge Cloudflare's cache through its API. More specially, the purge all files command. However, I keep running into the "Invalid Content-Type header, valid values are application/json,...

  1. purge cloudflare cache
  2. cloudflare purge cache api
  3. cloudflare purge cache not working
  4. cloudflare purge cache api php
  5. cloudflare purge cache wildcard
  6. cloudflare purge cache by url
  7. failed to purge cloudflare cache not authenticated
  8. how to purge cloudflare cache

We are building a form-based app that has a complex object with many levels of nested properties. So far, I have created a simple experiment with a single view model with one object. The experiment ...

We are building a form-based app that has a complex object with many levels of nested properties. So far, I have created a simple experiment with a single view model with one object. The experiment ...

  1. bind view model in mvc
  2. bind view model to view
  3. bind viewmodel extjs
  4. wpf bind to viewmodel
  5. bind view viewmodel xaml
  6. bind view to model backbone
  7. aurelia bind view-model
  8. bind partial view model
  9. bind property view model
  10. wpf bind viewmodel property
  11. bind view to viewmodel
  12. bind view to viewmodel android
  13. bind view to viewmodel wpf
  14. prism bind view viewmodel
  15. bind button to viewmodel
  16. android bind view to model
  17. bind button click to view model
  18. angular bind view to model
  19. razor bind view to model
  20. mvvm bind view to model

I have a menu have many items. I want to show only 5 items, other items will be hidden. When clicking next or previous button, it will show other items. Should be shown like this: Here is my demo ...

I have a menu have many items. I want to show only 5 items, other items will be hidden. When clicking next or previous button, it will show other items. Should be shown like this: Here is my demo ...

I'm trying to figure out a way to search for a Greek letter in a string replace it with another character. For example value = "Hello μ!"; value.replace("μ", "You"); alert(value); //Alerted value ...

I'm trying to figure out a way to search for a Greek letter in a string replace it with another character. For example value = "Hello μ!"; value.replace("μ", "You"); alert(value); //Alerted value ...