Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts

    how would i reload my page when data is saved?

    my code below goes off to: savetext.php and updates the database, how would I then on return to the page, be able to reload the page to view changes?

    thanks

    Code:
    <script>
    $(document).ready(function() {
    	function getQuerystring(key, default_)
    	{
    	  if (default_==null) default_="";
    	  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    	  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
    	  var qs = regex.exec(window.location.href);
    	  if(qs == null)
    	    return default_;
    	  else
    	    return qs[1];
    	}
    	var PageIDVal = getQuerystring('PageID');
    	var SiteIDVal = getQuerystring('SiteID');
    	     $('.edit').editable('http://localhost:8888/dhs/admin/savetext.php?PageID='+PageIDVal+'&SiteID='+SiteIDVal+'', { 
    	         id   : 'maincontent',
    	         name : 'textarea',
    	         type      : 'textarea',
    	         cancel    : 'Cancel',
    	         submit    : 'OK',
    	         indicator : 'Saving...',
    	         tooltip   : 'Click to edit...'
    	         
    	     });
    	 
    	 });
    	 	
    </script>

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,482
    Thanks
    6
    Thanked 981 Times in 954 Posts
    I don’t know what the editable function does but usually with an AJAX request there is a callback so you could initiate another AJAX request to just reload the section that has changed, or just do a simple window.location.reload()

  • #3
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thanks, I used:
    window.location.reload()

    but it's reloading the page all the time not just once?!

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,482
    Thanks
    6
    Thanked 981 Times in 954 Posts
    You have to execute that in the callback of the “editable” function (which I assume there is?), not on page load.

  • #5
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I put it in my code but it doesn't work?!

    Code:
         $('.edit').editable('http://localhost:8888/dhs/admin/savetext.php?PageID='+PageIDVal+'&SiteID='+SiteIDVal+'', { 
    	         id   : 'maincontent',
    	         name : 'textarea',
    	         type      : 'textarea',
    	         cancel    : 'Cancel',
    	         submit    : 'OK',
    	         indicator : 'Saving...',
    	         tooltip   : 'Click to edit...'
    	          window.location.reload()
    	     });

  • #6
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,482
    Thanks
    6
    Thanked 981 Times in 954 Posts
    Of course it’s not working because, as I said, it must be in a callback function, not just be put into the options like that. In fact, according to http://www.appelsiini.net/projects/jeditable there is an option called “callback” which takes a function as value:
    Code:
     $('.editable').editable('http://www.example.com/save.php', { 
         type     : 'textarea',
         submit   : 'OK',
         callback : function(value, settings) {
             console.log(this);
             console.log(value);
             console.log(settings);
         }
     });
    That is where the reload function must go.

  • #7
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I tried this, it doesn't work?!

    Code:
    $('.edit').editable('http://localhost:8888/dhs/admin/savetext.php?PageID='+PageIDVal+'&SiteID='+SiteIDVal+'', { 
    	         id   : 'maincontent',
    	         name : 'textarea',
    	         type      : 'textarea',
    	         cancel    : 'Cancel',
    	         submit    : 'OK',
    	         indicator : 'Saving...',
    	         tooltip   : 'Click to edit...'
    	         callback : function() {
    	          window.location.reload()
    		     }
    	     });

  • #8
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,482
    Thanks
    6
    Thanked 981 Times in 954 Posts
    Yes, because you forgot the comma after the tooltip option.

    Sometimes it also helps to consult the browser’s error console. It saves valuable time in asking questions and waiting for replies.

  • #9
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,189
    Thanks
    10
    Thanked 569 Times in 550 Posts
    why use an ajax submit only to reload the page once it submits?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •