Mostrando entradas con la etiqueta JavaScript. Mostrar todas las entradas
Mostrando entradas con la etiqueta JavaScript. Mostrar todas las entradas
viernes, 15 de noviembre de 2013
Convertir un Array de Objetos Javascript a JSon
I made it that way:
if I have:
var jsonArg1 = new Object();
jsonArg1.name = 'calc this';
jsonArg1.value = 3.1415;
var jsonArg2 = new Object();
jsonArg2.name = 'calc this again';
jsonArg2.value = 2.73;
var pluginArrayArg = new Array();
pluginArrayArg.push(jsonArg1);
pluginArrayArg.push(jsonArg2);
to convert pluginArrayArg (which is pure javascript array) into JSON array:
var jsonArray = JSON.parse(JSON.stringify(pluginArrayArg))
Gracias al aporte de:
http://stackoverflow.com/questions/2295496/convert-array-to-json
Como se hace en AJAX:
$.ajax({
url:"contextPath/data",
type:"POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(pluginArrayArg) , //Stringified Json Object
async: false, //Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation
cache: false, //This will force requested pages not to be cached by the browser
processData:false, //To avoid making query String instead of JSON
success: function(resposeJsonObject){
alert(resposeJsonObject);
}});
lunes, 9 de abril de 2012
miércoles, 14 de septiembre de 2011
viernes, 22 de abril de 2011
martes, 29 de marzo de 2011
Detectar el tipo de una variable en Javascript
Código JavaScript:
var _getType = function( inp ) {
var type = typeof inp, match;
var key;
if (type == 'object' && !inp) {
return 'null';
}
if (type == "object") {
if (!inp.constructor) {
return 'object';
}
var cons = inp.constructor.toString();
if (match = cons.match(/(\w+)\(/)) {
cons = match[1].toLowerCase();
}
var types = ["boolean", "number", "string", "array"];
for (key in types) {
if (cons == types[key]) {
type = types[key];
break;
}
}
}
return type;
};
Ver Articulo completo
var _getType = function( inp ) {
var type = typeof inp, match;
var key;
if (type == 'object' && !inp) {
return 'null';
}
if (type == "object") {
if (!inp.constructor) {
return 'object';
}
var cons = inp.constructor.toString();
if (match = cons.match(/(\w+)\(/)) {
cons = match[1].toLowerCase();
}
var types = ["boolean", "number", "string", "array"];
for (key in types) {
if (cons == types[key]) {
type = types[key];
break;
}
}
}
return type;
};
Ver Articulo completo
sábado, 15 de mayo de 2010
Cómo cerrar una etiqueta de Script
Si tu código javascript no se ejecuta, puede que no hayas cerrado bien la etiqueta SCRIPT
revisa este articulo para ver la solución:
http://my.opera.com/el-isra/blog/html-cerrar-etiqueta-script
revisa este articulo para ver la solución:
http://my.opera.com/el-isra/blog/html-cerrar-etiqueta-script
martes, 19 de enero de 2010
Mejores Practicas JavaScript II
Como validar formularios de forma eficiente.
Ver Link:
http://www.smashingmagazine.com/2009/07/07/web-form-validation-best-practices-and-tutorials/
Ver Link:
http://www.smashingmagazine.com/2009/07/07/web-form-validation-best-practices-and-tutorials/
Suscribirse a:
Entradas (Atom)