TypeError:a未定义 [英] TypeError: a is undefined

查看:95
本文介绍了TypeError:a未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 $。每个方法时,我在jQuery v1.7.2代码上遇到上述错误:

I get the above error on the jQuery v1.7.2 code when I try to use the $.each method:

$.post('url_of_php_file.php',
            $.param( {

            }),
            function(data){
                $.each(data.articles, function(index, value){
                .....
});

请求返回:

{"articles": [
    {
        "id":"11",
        "date":"2012-12-19 15:52:06",
        "title":"url_title",
        "link":"url_link",
        "available":"1"
     },
    ..... *more rows like the above*
]}

为什么会出现此错误?

推荐答案

你做的事情在jQuery中引起了一个错误。这是你代码中99.9%的错误,而不是jQuery中的错误。

Something you did caused an error inside jQuery. This is 99.9% of the time a bug in your code and not a bug in jQuery.

使用jQuery的开发版本有什么帮助。它不是m inified,这意味着它仍然具有完整的变量名称,而不是 a b 等。

What helps is using the development version of jQuery. It is not minified, which means that it still has the full variable names instead of a, b, etc.

您是否发送了:

header('Content-Type: application/json');

echo json_encode($ data); ?这将触发jQuery的JSON检测。在 $。每个之前添加 console.log(data); 以确认数据看起来像您期望的那样。

before the echo json_encode($data);? That would triggers jQuery's JSON detection. Add a console.log(data); before the $.each to confirm the data looks like you'd expect.

这篇关于TypeError:a未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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