MooTools:如何直接使用responseText

发布于 2024-10-10 09:49:40 字数 539 浏览 5 评论 0原文

在下面的代码示例中,我想遍历responseText对象,其中包含来自request_page.php文件的html代码。在 onSuccess 事件中,我想检查是否 <分区> id 'ersDiv' 中发布了任何错误。

new Request.HTML({
    url: 'request_page.php',
    onSuccess: function(responseText, responseXML) {
    // My expected code to handle responseText object
    alert(errorMessage);
    },
    onFailure: function() {  }
});

request_page.php 文件是这样的:

<div align='center'><div id='ersDiv'>Page loaded with insufficient data</div></div>

In following example of code, I want to traverse the responseText object which consist the html code came from request_page.php file. In onSuccess event, i want to check whether < Div > with id 'ersDiv' has any errors posted in it.

new Request.HTML({
    url: 'request_page.php',
    onSuccess: function(responseText, responseXML) {
    // My expected code to handle responseText object
    alert(errorMessage);
    },
    onFailure: function() {  }
});

request_page.php file is like this :

<div align='center'><div id='ersDiv'>Page loaded with insufficient data</div></div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遥远的绿洲 2024-10-17 09:49:41

在 1.2.x 上尝试一下(针对 jsfiddle api 进行调整的示例):

new Request.HTML({
    url: '/echo/html/',
    method: "post",
    data: {
        html: "<div align='center'><div id='ersDiv'>Page loaded with insufficient data</div></div>",
        delay: 1
    },
    onComplete: function(responseText, responseXML) {
        var error, errors = responseXML.getElements("div").filter(function(el) {
            return el.get("id") == "ersDiv";
        });

        if (errors.length) {
            error = errors[0].get("text");
            alert(error);
        }
    }
}).send();

工作示例:

http://www.jsfiddle.net/dimitar/vLgqB/" jsfiddle.net/dimitar/vLgqB/

在 1.3 中,这可以按照 oskar 的建议工作:

console.log($(this.response.tree).getElement("#ersDiv")[0].get("text"));

http ://www.jsfiddle.net/dimitar/vLgqB/2/

玩得开心。

try this for 1.2.x (example tweaked for the jsfiddle api):

new Request.HTML({
    url: '/echo/html/',
    method: "post",
    data: {
        html: "<div align='center'><div id='ersDiv'>Page loaded with insufficient data</div></div>",
        delay: 1
    },
    onComplete: function(responseText, responseXML) {
        var error, errors = responseXML.getElements("div").filter(function(el) {
            return el.get("id") == "ersDiv";
        });

        if (errors.length) {
            error = errors[0].get("text");
            alert(error);
        }
    }
}).send();

working example:

http://www.jsfiddle.net/dimitar/vLgqB/

in 1.3 this can work as oskar suggested:

console.log($(this.response.tree).getElement("#ersDiv")[0].get("text"));

http://www.jsfiddle.net/dimitar/vLgqB/2/

have fun.

单身情人 2024-10-17 09:49:41
function(responseText, responseXML) {
  if (responseText.getElement('#ersDiv').get('text') === 'Page loaded with insufficient data'){
    console.log('There was an error');
  }
}

顺便提一句。 1990 年召唤而来,他们希望 align='center' 回来:-)

function(responseText, responseXML) {
  if (responseText.getElement('#ersDiv').get('text') === 'Page loaded with insufficient data'){
    console.log('There was an error');
  }
}

Btw. 1990 called, they want their align='center''s back :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文