简体   繁体   English

jQuery还会在ajax调用的末尾附加代码吗?

[英]wht does jQuery also append code to the end of an ajax call?

Can anyone tell my what this is that jquery has added to the end of my output to "posts-container" and how to fix it? 谁能告诉我这是jquery在我的输出中添加到“ posts-container”末尾的内容,以及如何解决它? Its not coming from the json so what is the issue. 它不是来自json的问题是什么。 code is below and the output is adding at the end. 代码在下面,输出在末尾添加。

Thanks in advance. 提前致谢。

$(document).ready(function(){
        $('#waiting').show(500);
        $('#message').hide(0);

        $.ajax({
            type: 'get',
            url: 'http://domain.com/api/index.php/id/18271',
            dataType: 'json',
            data: 'apiKeytest=1',
            success: function(r){
                var output = '';
                for (a in r.DATA) {
                    for (b in r.DATA[a]) {
                        if (typeof(r.DATA[a][b]) == 'object') {
                            for (c in r.DATA[a][b]) {
                                output += c + ' = ' + r.DATA[a][b][c] + '<br />';
                            }
                        }
                        else {
                            output += b + ' = ' + r.DATA[a][b] + '<br />';
                        }
                    }
                }
                jQuery('#posts-container').append(output);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                $('#waiting').hide(500);
                $('#message').removeClass().addClass('error').text('There was an error.').show(500);

            }
        });

        return false;
    });

output has this at the end 输出在末尾有这个

argumentNames = function () { var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip"); return names.length == 1 && !names[0] ? [] : names; }
bindAsEventListener = function () { var __method = this, args = $A(arguments), object = args.shift(); return function (event) {return __method.apply(object, [event || window.event].concat(args));}; }
curry = function () { if (!arguments.length) { return this; } var __method = this, args = $A(arguments); return function () {return __method.apply(this, args.concat($A(arguments)));}; }
delay = function () { var __method = this, args = $A(arguments), timeout = args.shift() * 1000; return window.setTimeout(function () {return __method.apply(__method, args);}, timeout); } etc............

the json json

{
    "ERRORS": [],
    "DATA": [
        {
            "itemActive": true,
            "itemTxt": "test",
            "itemID": "30d2f2c1-58ca-4b3d-b3e0-d284ae5b25ab",
            "itemValidTo": "October, 19 2011 00:00:00",
            "itemName": "test",
            "itemCreated": "October, 03 2011 00:00:00",
            "image": {
                "imageCreated": "October, 05 2011 00:00:00",
                "imageURL": "test.jpg",
                "imageID": "bc869a94-fee5-4fc8-bd21-e2de2f020310"
            },
            "itembio": 53.0650849
        }
    ],
    "MESSAGES": [
        {
            "TOTAL": 1,
            "CURRENTPAGE": 1,
            "TOTALPAGES": 1
        }
    ]
}

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/hasOwnProperty https://developer.mozilla.org/zh-CN/JavaScript/Reference/Global_Objects/Object/hasOwnProperty

So you are probably using some library or maybe your own code extends the native object. 因此,您可能正在使用某些库,或者您自己的代码扩展了本机对象。

Witch is the functions that appears in the output. Witch是显示在输出中的功能。 (toString of a function gives you its code) (函数的toString为您提供其代码)

You can get around it by checking if the property is from the object or its prototype with this call. 您可以通过调用此属性来检查属性是否来自对象或其原​​型,从而解决该问题。

 if(obj.hasOwnProperty(key)) {
   // you have a property from the object
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM