This is the first time that I have consulted in this forum so I will try to be precise: The idea is to extract tweets from the internet: I have taken an internet example and it fails me. This is the script where I try to extract:
$('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');
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-migrate-1.2.1.js" crossorigin="anonymous"></script>
<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>
The error that jumps in the chrome console is this:
jquery.min.js:4 Uncaught RangeError: Maximum call stack size exceeded at Vc (jquery.min.js:4) at Vc (jquery.min.js:4) at Vc (jquery.min.js:4) at Vc (jquery.min.js:4) at Vc (jquery.min.js:4) at Vc (jquery.min.js:4) at Vc (jquery.min.js:4) at Vc (jquery.min.js:4) at Vc (jquery.min.js:4) at Vc (jquery.min.js:4)
Any suggestions. PD: I hope this time if I'm doing the consultation well