如何在具有相同名称的预先存在的标记上附加ajax数据 [英] How do I append ajax data on preexisting tag with same name

查看:64
本文介绍了如何在具有相同名称的预先存在的标记上附加ajax数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当页面加载时,所需的部分(即我打算将内容加载到的部分)清空,但 console.log 清楚地显示 x 带有内容,只是拒绝放弃。



我尝试了什么:



表格发布到同一页面,页面返回时带有相同的标记但已处理的数据来自提交的表格。

代码如< br $> b $ b

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

$.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





我已经尝试 find()其他元素而不是部分,就像我尝试了部分后代一样页面上存在的其他标签,甚至是页脚;他们都被追加,但由于一些奇怪的原因,部分拒绝遵守。

我也试过打开 x 并使用追加函数签名将其外部HTML传递给部分。它也不起作用。我该怎么办?



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?

推荐答案

.post(url,
.post(url,


' form')。serialize(), function (data){
var h =
('form').serialize(), function (data) { var h =


' < div />')。html(数据),x =
('<div/>').html(data), x =


这篇关于如何在具有相同名称的预先存在的标记上附加ajax数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆