JQuery - Uncaught RangeError: Maximum call stack size exceeded

 
Vista:
sin imagen de perfil

Uncaught RangeError: Maximum call stack size exceeded

Publicado por Victor (20 intervenciones) el 20/05/2018 15:59:06
Buenas tardes.

Intento hacer una extraccion de tweets desde la web.
El codigo del ejemplo no me funciona y me dá como error "Uncaught RangeError: Maximum call stack size exceeded" y hace referencia al fichero JSON.
Este es el codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<html>
    <head>
        <title>Sample twitter</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
        <script src="https://code.jquery.com/jquery-migrate-1.2.1.js" crossorigin="anonymous"></script>
        <script>
            $('document').ready(function (){
                //Disallow hiding the Ajax loading modal that pops up when searching
                //Impedir ocultar el modo de carga de ajax que aparece cuando se busca.
                var allowAjaxHide=false;
                var hideFunction=function (event){
                    if(!allowAjaxHide){
                        event.preventDefault();
                    }
                    allowAjaxHide=false;
                };
                $('#ajaxIndicator').on('hide.bs.modal',hideFunction)
 
 
                //Perform a twitter search when the "pulbic search" form is submitted
                //Realice una búsqueda en Twitter cuando se envíe el formulario de "búsqueda pública"
                $('#getposts_form').submit(function (event){
                   event.preventDefault();
 
                   //clear out our output areas first
                   //Limpiar nuestra area de salida primero
 
                   $('#output').empty();
                   $('#errors').empty();
 
                   var search=$("#search").val();//.val() se usa para asignar y obtener valor de inputs,select y textArea
                   var language=$("#lang").val();
                   var resulttype=$("#resulttype").val();
                   console.log(search);
                   console.log(language);
                   console.log(resulttype);
 
                   //Validate all form inputs,as needed
                   //Valide todas las entradas de formulario, según sea necesario
                   var errorMessage='';
                   var emptyStringPattern=  /^\s*$/;
 
                   if(emptyStringPattern.test(search)){
                       errorMessage="You must enter a search terms.";//Debes ingresar un termino de busqueda
                   }
                   //api/index.php/TwitterAppOnly/search/tweets.json
                   if(errorMessage.length>0){
                       //When there are any validation errors,quit before the ajax call is made
                       //Cuando hay algún error de validación, salga antes de que se realice la llamada ajax
                       $('#errors').text(errorMessage);
                       return;
                   }
                });
 
 
            $.ajax({
                url:'https://api.twitter.com/1.1/search/tweets.json',
                data:{
                    q : search,
                    lang: lang,
                    result_type: resulttype,
                },
                success: function (serverResponse){
                    try{
                        console.log(serverResponse);
                        var statuses= serverResponse.statuses;
                        for(var i=0;i<statuses.length;i++){
                            var tweets= statuses[i];
                            //get template and copy it
                            var template=$($('#tweet').prop("content")).children().clone();
 
                            template.find(".body").text(tweet.text);
                            template.find(".user").text('@'+text.user.screen_name);
                            template.find(".favorites").text(tweet.favorite_count);
                            template.find(".retweets").text(tweet.retweet_count);
 
                            $("#output").append(template);
                        }
                    }catch(e){
                        console.error(ex);
                                        //An error ocurred processing the data from twitter
                        $('#error').text("Se ha producido un error en el estraccion de datos desde twitter");
                    }
                },
                error: function (jqXHR,textStatus,errorThrown){
                    if(errorThrown=='Service Unavailable'){
                        $("#errors").text("Your cloud 9 instance isn't running");
                    }else{
                        $("#error").text('An unknown error ocurred: '+errorThrown);
                    }
                },
                complete : function (){
                    //
                    allawAjaxHide= true;
                    $("#ajaxIndicator").modal('hide');
                }
            });
 
            //let the user know something is happening in the meantime
            //permitir que el usuario sepa algo de lo qu está suceciendo
            $("#ajaxIndicator").modal('show');
        });
 
        </script>
    </head>
    <body>
        <div class="container">
            <h1>Twitter Sample-Extraccion datos Twitter</h1>
            <div class="row">
                <div class="col-md-6">
                    <h2>Public Serach/Busqueda Publica</h2>
 
                    <form id="getposts_form" role="form">
                        <div class="form-group">
                            <label for="search">Search/Buscar</label>                                   <!--Ingrese los terminos de busqueda para buscar tweets-->
                            <input type="text" class="form-control" id="search" name="search" placeholder="(Enter search terms to search tweets)">
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <label for="lang">Language</label>
                                <select class="form-control" id="lang">
                                    <option value="">Any</option>
                                    <option value="en">English</option>
                                    <option value="es">Spain</option>
                                    <option value="zh">Chinese</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <label for="type">Result Type</label>
                            <select class="form-control" id="resulttype">
                                <option value="">Any</option>
                                <option value="mixed">Mixed</option>
                                <option value="recent">Recent</option>
                                <option value="popular">Popular</option>
                            </select>
                        </div>
                        <br>
                        <button class="btn btn-default" type="submit" id="submit">Submit</button>
                    </form>
                </div>
                <div class="col-md-6">
                    <h2>Results:</h2>
                    <div id="errors"></div>
                    <ul id="output" class="list-group"></ul>
                    <template id="tweet">
                        <li class="tweet list-group-item">
                            <span class="user">{{user}}</span>
                            <span class="body">{{tweet}}</span>
                            <span class="retweets badge">{{retweets}}</span>
                            <span class="favorite badge">{{favorites}}</span>
                        </li>
                    </template>
                </div>
            </div>
            <div class="modal" id="ajaxIndicator" data-keyboard="false">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-body">
                            <p>Please wait......</p>
                            <p>
                                <img src="images/ajax-loader-gif-6.gif">
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

Alguien ha hecho esto de extraer tweets alguna vez?

Saludos.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder