Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
When the page loads, the desired section (i.e the section I intend loading content into) is emptied but console.log clearly shows that x carries content and simply refuses to give it up.

What I have tried:

The form is posted to this same page and the page is returned with the same markup but processed data from the submitted form.
The code is such as

JavaScript
$.post(url, $('form').serialize(), function (data) {
	var h = $('<div/>').html(data), x = $('body').append(h).find($('div section'))
	console.log(x, x.text())
	
	$('main > section').empty().append(x);

	h.remove();
})

$('[name="bio_submit"]').click(); // auto submit form on load
// manually submitting the form produces the same result also


I've tried find()ing other elements instead of section, like I've tried section descendants and also other tags existing on the page, even the footer; they all get appended but for some strange reason, section refuses to comply.
I've also tried unwrapping x and passing its outer HTML unto section using append function signature. It doesn't work either. How do I go about it?
Posted
Updated 8-May-17 4:18am
Comments
F-ES Sitecore 8-May-17 9:16am    
We don't know what is in "data" so it's hard to give any concrete help.
nmeri17 8-May-17 9:51am    
Data contains the entire page. I said "The form is posted to this same page and the page is returned with the same markup but processed data from the submitted form." so the exact same page from the doctype declaration down to footer is sent in the data

1 solution

Oddly, this works

JavaScript
$.post(url, $('form').serialize(), function (data) {
 var z = $('main > section').empty(),
 h = $('<div/>').html(data),
 x = $('body').append(h).find($('div section'))
				
 z.append(x);
 h.remove();
})


Meanwhile, you might want to remove this line $('[name="bio_submit"]').click() since it fires automatically every time the DOM loads that `section`.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900