Ver Mensaje Individual
  #5 (permalink)  
Antiguo 27/08/2011, 13:02
Avatar de morfasto
morfasto
 
Fecha de Ingreso: julio-2011
Ubicación: Lima
Mensajes: 291
Antigüedad: 12 años, 9 meses
Puntos: 8
Respuesta: SyntaxError: Unexpected token <

json2.js
Código Javascript:
Ver original
  1. if (!this.JSON) {
  2.     JSON = {};
  3. }
  4. (function () {
  5.  
  6.     function f(n) {
  7.         return n < 10 ? '0' + n : n;
  8.     }
  9.  
  10.     if (typeof Date.prototype.toJSON !== 'function') {
  11.  
  12.         Date.prototype.toJSON = function (key) {
  13.  
  14.             return this.getUTCFullYear()   + '-' +
  15.                  f(this.getUTCMonth() + 1) + '-' +
  16.                  f(this.getUTCDate())      + 'T' +
  17.                  f(this.getUTCHours())     + ':' +
  18.                  f(this.getUTCMinutes())   + ':' +
  19.                  f(this.getUTCSeconds())   + 'Z';
  20.         };
  21.  
  22.         String.prototype.toJSON =
  23.         Number.prototype.toJSON =
  24.         Boolean.prototype.toJSON = function (key) {
  25.             return this.valueOf();
  26.         };
  27.     }
  28.  
  29.     var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  30.         escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  31.         gap,
  32.         indent,
  33.         meta = {
  34.             '\b': '\\b',
  35.             '\t': '\\t',
  36.             '\n': '\\n',
  37.             '\f': '\\f',
  38.             '\r': '\\r',
  39.             '"' : '\\"',
  40.             '\\': '\\\\'
  41.         },
  42.         rep;
  43.  
  44.  
  45.     function quote(string) {
  46.         escapable.lastIndex = 0;
  47.         return escapable.test(string) ?
  48.             '"' + string.replace(escapable, function (a) {
  49.                 var c = meta[a];
  50.                 return typeof c === 'string' ? c :
  51.                     '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  52.             }) + '"' :
  53.             '"' + string + '"';
  54.     }
  55.  
  56.  
  57.     function str(key, holder) {
  58.         var i,
  59.             k,
  60.             v,
  61.             length,
  62.             mind = gap,
  63.             partial,
  64.             value = holder[key];
  65.  
  66.         if (value && typeof value === 'object' &&
  67.                 typeof value.toJSON === 'function') {
  68.             value = value.toJSON(key);
  69.         }
  70.  
  71.         if (typeof rep === 'function') {
  72.             value = rep.call(holder, key, value);
  73.         }
  74.  
  75.         switch (typeof value) {
  76.         case 'string':
  77.             return quote(value);
  78.  
  79.         case 'number':
  80.  
  81.             return isFinite(value) ? String(value) : 'null';
  82.  
  83.         case 'boolean':
  84.         case 'null':
  85.  
  86.             return String(value);
  87.  
  88.         case 'object':
  89.  
  90.             if (!value) {
  91.                 return 'null';
  92.             }
  93.  
  94.             gap += indent;
  95.             partial = [];
  96.  
  97.             if (Object.prototype.toString.apply(value) === '[object Array]') {
  98.  
  99.                 length = value.length;
  100.                 for (i = 0; i < length; i += 1) {
  101.                     partial[i] = str(i, value) || 'null';
  102.                 }
  103.  
  104.                 v = partial.length === 0 ? '[]' :
  105.                     gap ? '[\n' + gap +
  106.                             partial.join(',\n' + gap) + '\n' +
  107.                                 mind + ']' :
  108.                           '[' + partial.join(',') + ']';
  109.                 gap = mind;
  110.                 return v;
  111.             }
  112.  
  113.             if (rep && typeof rep === 'object') {
  114.                 length = rep.length;
  115.                 for (i = 0; i < length; i += 1) {
  116.                     k = rep[i];
  117.                     if (typeof k === 'string') {
  118.                         v = str(k, value);
  119.                         if (v) {
  120.                             partial.push(quote(k) + (gap ? ': ' : ':') + v);
  121.                         }
  122.                     }
  123.                 }
  124.             } else {
  125.  
  126.                 for (k in value) {
  127.                     if (Object.hasOwnProperty.call(value, k)) {
  128.                         v = str(k, value);
  129.                         if (v) {
  130.                             partial.push(quote(k) + (gap ? ': ' : ':') + v);
  131.                         }
  132.                     }
  133.                 }
  134.             }
  135.  
  136.             v = partial.length === 0 ? '{}' :
  137.                 gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
  138.                         mind + '}' : '{' + partial.join(',') + '}';
  139.             gap = mind;
  140.             return v;
  141.         }
  142.     }
  143.  
  144.     if (typeof JSON.stringify !== 'function') {
  145.         JSON.stringify = function (value, replacer, space) {
  146.  
  147.             var i;
  148.             gap = '';
  149.             indent = '';
  150.  
  151.             if (typeof space === 'number') {
  152.                 for (i = 0; i < space; i += 1) {
  153.                     indent += ' ';
  154.                 }
  155.  
  156.             } else if (typeof space === 'string') {
  157.                 indent = space;
  158.             }
  159.  
  160.  
  161.             rep = replacer;
  162.             if (replacer && typeof replacer !== 'function' &&
  163.                     (typeof replacer !== 'object' ||
  164.                      typeof replacer.length !== 'number')) {
  165.                 throw new Error('JSON.stringify');
  166.             }
  167.  
  168.             return str('', {'': value});
  169.         };
  170.     }
  171.  
  172.     if (typeof JSON.parse !== 'function') {
  173.         JSON.parse = function (text, reviver) {
  174.  
  175.             var j;
  176.  
  177.             function walk(holder, key) {
  178.  
  179.                 var k, v, value = holder[key];
  180.                 if (value && typeof value === 'object') {
  181.                     for (k in value) {
  182.                         if (Object.hasOwnProperty.call(value, k)) {
  183.                             v = walk(value, k);
  184.                             if (v !== undefined) {
  185.                                 value[k] = v;
  186.                             } else {
  187.                                 delete value[k];
  188.                             }
  189.                         }
  190.                     }
  191.                 }
  192.                 return reviver.call(holder, key, value);
  193.             }
  194.  
  195.             cx.lastIndex = 0;
  196.             if (cx.test(text)) {
  197.                 text = text.replace(cx, function (a) {
  198.                     return '\\u' +
  199.                         ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  200.                 });
  201.             }
  202.  
  203.             if (/^[\],:{}\s]*$/.
  204. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  205. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  206. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  207.  
  208.                 j = eval('(' + text + ')');
  209.  
  210.  
  211.                 return typeof reviver === 'function' ?
  212.                     walk({'': j}, '') : j;
  213.             }
  214.  
  215.             throw new SyntaxError('JSON.parse');
  216.         };
  217.     }
  218. }());

Lo que hace el codigo es cargar una ruta que esta guardada en la base de datos y mostrarla en el ver.php

Espero me puedan ayudar!

Muchas gracias!