IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

Status: parsererror, Error Thrown: SyntaxError: Unexpected number


Sujet :

jQuery

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2014
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Juillet 2014
    Messages : 17
    Points : 17
    Points
    17
    Par défaut Status: parsererror, Error Thrown: SyntaxError: Unexpected number
    Bonjour,

    J'ai developpé un script en ajax pour filtrer des données lors de l'affichage cependant j'ai toujours ce message d'erreur Status: parsererror, Error Thrown: SyntaxError: Unexpected number qui s'affiche et je ne comprend pas

    Besoin d'aide svp.

    Le code ci dessous

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    /*! AjaxSelectOption 1.0.0-dev
    * ©2014 LifeOfData Inc - lifeofdata.com/license
    */
     
    /*
     * @summary SelectOptAjax
     * @description dynamic completion of select box with remote data on change
     * @version 1.0.0-dev
     * @file selectedOptAjax.js
     * @author Jean-Marc Christfried BALIZOU
     * @contact fr.linkedin.com/pub/jean-m-christfried-balizou/5a/5b3/bb8/
     * @copyright Copyright 2014 LifeOfData Inc <christfriedbalizou@gmail.com>.
     *
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     * 
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
     * MA 02110-1301, USA.
     * 
     * 
     */
    (function($){
     
        $.fn.selectOptAjax = function(options){
            /*
             * @Variable: defaults
             * @Purpose : Storage of default parameters, used for selectOptAjax
             * @Function : $.fn.selectOptAjax 
             */
            var defaults = {
                destination : null,
                serverUrl : null,
                serverFlag : null           
            };
     
            /*
             * @Variable: settings
             * @Purpose : Storage of settings parameters
             * @Function : $.fn.selectOptAjax 
             */
            var settings = $.extend(true, {}, defaults, options);
     
            /* Check if the parameters are not null */
            var exit = settings.destination  == null 
                            ? false : settings.serverUrl == null 
                            ? false : settings.serverFlag == null ? false : true
     
     
            /* If false exit the plugin */
            if(!exit){
                console.log("Error, initialize all the parameters");
                alert("Error, initialize all the parameters");
                return $(this);
            } 
     
            /* Binding on change action of current element */
            return $(this).on('change', function(event){
     
                /* Disabling the default behavior on the element */
                event.preventDefault();
     
                /* Starting ajax process */
                $.ajax({
                    url : settings.serverUrl,
                    type : "GET",
                    dataType : "json",
                    data : [{"name" : settings.serverFlag, "value" : $("option:selected", this).val()}],
                    success : function(data){
     
                        /* Clearing previous data */
                        $(settings.destination).empty();
     
                        console.log(data);
     
                        /* Looping and adding new data from serveur 
                        for(var i = 0; i < data.length; i++){
                            $(settings.destination).append(
                                    $("<option/>", {
                                        value : data[i],
                                        text : data[i]
                                    })
                            );
                        }*/
                    },
                    error : function( jqXHR, textStatus, errorThrown ){
                        console.error("Status: " + textStatus + ", Error Thrown: " + errorThrown);
                        alert("Status: " + textStatus + ", Error Thrown: " + errorThrown);
                    }
                });
            });
        }
    })(jQuery);

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Mars 2002
    Messages
    1 132
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 132
    Points : 1 418
    Points
    1 418
    Par défaut
    Bonsoir,

    dataType = "json" implique que la réponse va être automatiquement convertie en objet.
    Ton message indique que la réponse n'a pas un format valide pour le parseur JSON.

    Il faut donc que tu regardes le contenu de la réponse AJAX, pas le code JavaScript.


    devYan.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2014
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Juillet 2014
    Messages : 17
    Points : 17
    Points
    17
    Par défaut
    Bonjour,

    Merci beaucoup ta réponse m'a beaucoup aidé dans la résolution de mon problème était d'encoder le résultat en JSON lors de l'affichage

    Cordialement

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 13
    Dernier message: 17/09/2014, 14h32
  2. Error not valid port number or address
    Par kavdo34 dans le forum Général Python
    Réponses: 1
    Dernier message: 28/05/2013, 16h16
  3. [XSLT 1.0] Error in expression : Unexpected token EOF in expression
    Par djibril dans le forum XSL/XSLT/XPATH
    Réponses: 3
    Dernier message: 11/12/2012, 10h50
  4. [Webservices] error Axis Subelement Unexpected
    Par lothar59 dans le forum Services Web
    Réponses: 0
    Dernier message: 03/01/2011, 10h50
  5. Réponses: 3
    Dernier message: 05/12/2007, 19h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo