I am successfully posting a form via ajax, using the following code;
我正在使用以下代码通过ajax成功发布表单;
$.post( "Page.do?source=ajax",
$("#Form").serialize(),
function(data){
}
The data response that comes back can be alert'd. I can see that it is the HTML of the entire form, having been submitted. But, I am having trouble accessing an element in that form which has come via ajax, ie
返回的数据响应可以是警报。我可以看到它是整个表单的HTML,已经提交。但是,我无法访问通过ajax获得的那种形式的元素
data.find('.Errors').html()
or
或
$('.Errors', data).html()
Do I need to somehow convert the text into a DOM which can then be parsed by jQuery?
我是否需要以某种方式将文本转换为DOM,然后由jQuery解析?
2 个解决方案
#1
2
Correct, otherwise you would have to apply regex to the result (which is a string and not a DOM).
正确,否则您必须将regex应用到结果(它是一个字符串,而不是DOM)。
You can convert it to DOM by:
您可以将其转换为DOM:
$(data)
and then applying any jQuery you want to it.
然后应用你想要的jQuery。
#2
1
Do I need to somehow convert the text into a DOM which can then be parsed by jQuery?
我是否需要以某种方式将文本转换为DOM,然后由jQuery解析?
Yes you do:
是的,你做的事:
$(data).find('.Errors').html();
美元(数据);(' . error '). html();
Although normally using data as the scope for the selector like you showed in your second example should work.
尽管通常使用数据作为选择器的范围,如您在第二个示例中所显示的那样,应该可以工作。
#1
2
Correct, otherwise you would have to apply regex to the result (which is a string and not a DOM).
正确,否则您必须将regex应用到结果(它是一个字符串,而不是DOM)。
You can convert it to DOM by:
您可以将其转换为DOM:
$(data)
and then applying any jQuery you want to it.
然后应用你想要的jQuery。
#2
1
Do I need to somehow convert the text into a DOM which can then be parsed by jQuery?
我是否需要以某种方式将文本转换为DOM,然后由jQuery解析?
Yes you do:
是的,你做的事:
$(data).find('.Errors').html();
美元(数据);(' . error '). html();
Although normally using data as the scope for the selector like you showed in your second example should work.
尽管通常使用数据作为选择器的范围,如您在第二个示例中所显示的那样,应该可以工作。