Position:fixed; after serialize()

There was a small problem. There is a page where the form is submitted this code:
$(function(){<br> $('.add-form > form').submit(function(){<br> var thisForm = $(this);<br> var url = thisForm.attr('action');<br> var url = url.substr(0,url.indexOf('#'));<br> var data = thisForm.the serialize()+'&add=1';<br> $.post(url, data, function(content){<br> $('body').html(content);<br> });<br> return false;<br> });<br> <br / > });

on the page there is an element that when scale gets position:fixed; with

$(function() {<br> var div = $('#fixed-top');<br> var start = $(div).offset().top;<br> $.event.add(window, "scroll", function() {<br> var p = $(window).scrollTop();<br> $(div).css('position',((p)>start) ? 'fixed' : 'static');<br> $(div).css('top',((p)>start) ? '0px' : ");<br> });<br> <br / > });

ACC. when you submit a form the fixed element is hidden. Please tell me, how can we avoid this? Thank you!
October 8th 19 at 02:35
2 answers
October 8th 19 at 02:37
I could be wrong, but apparently the problem is in this line:
$('body').html(content);

Try to fix it on
$('body').append(content);
Thanks, but unfortunately did not help, is not working refresh the page (i.e., the items inside are not updated in the end) - Brenden.Harvey commented on October 8th 19 at 02:40
Can you provide a link to your page?
Or more, describe what is being passed via Ajax to the variable content and where the page uses the contents of that variable.

If the content you have transferred all the contents of the page, then try to do
HTML:

 <div id="fixed-top"> Fixed element </div>
 <div id="content"> This content will be replaced via Ajax </div>



Javascript:
$('#content').html(content);
- Toni_Runolfss commented on October 8th 19 at 02:43
Unfortunately the page while on the local server. The problem is that when you submit a form changing several blocks, tried to write
$('header section').html(content);
but it does not work correctly, for some reason, appear to duplicate elements - Brenden.Harvey commented on October 8th 19 at 02:46
Duplicates will because the row $('header section').html(content); adds the contents of the content in the header and in section.

To make this idea work, you need to separate the content into 2 header variables and section. Continue to work with them:
$('header').html(header);
$('section').html(section); - Toni_Runolfss commented on October 8th 19 at 02:49
So all right, after all you are adding content all the tags header and section - laura37 commented on October 8th 19 at 02:52
Sorry, didn't notice that this has already been said :) - laura37 commented on October 8th 19 at 02:55
October 8th 19 at 02:39
Upgrading multiple units via Ajax can be implemented in the following way:
$.post(url, data, function(content)
{
 // data from the server must come in JSON (i.e. {"header":"code inside the block header", "section":"code block inside section"})
$('header').html(content.header);
$('section').html(content.section);

 // if rewrite the code on the server is not possible, you have to pull the right data from the content using regexps
 // var header = /
(.+)<\/header>/gi.exec(content); // var section = /
(.+)<\/section>/gi.exec(content); // $('header').html(header[1]); // $('section').html(section[1]); }, 'json');
There is a method .load()

$('#header').load(url + '#header');


inappropriately and no regexps. The only disadvantage is that for each block there will be a separate request to the server - Brenden.Harvey commented on October 8th 19 at 02:42
I will try without regexps, now at nightfall, hurriedly, did not work. Thank you! - Toni_Runolfss commented on October 8th 19 at 02:45

Find more questions by tags jQuery