jeudi 24 mars 2016

How to compare two strings in Jquery/Js [duplicate]

This question already has an answer here:

I have following Javascript

 <script>
        var socket = io.connect('http://localhost:8080');
        socket.on('callback', function (data) {
            var message = data.split("_"); 
            var myid = "<?php echo Auth::user()->empid; ?> ";
                myid = myid.toString();

                //alert($.type(myid)+'-'+$.type(message[0]));

            if(myid == message[0]){
              alert(message[0]);
            $( "#callback" ).append( "<p>"+message[1]+"</p>" );
          }
          });
    </script>

What I am trying to do is when the socket connects

I am sending message in following format

userid_textmessage

Example would be

MIT818_You have got a message from ram C

Now in the javascript I am trying to compare like this

var message = data.split("_"); 
var myid = "<?php echo Auth::user()->empid; ?>";

if(myid == message[0])
alert(something);

So now even though the myid and message[0] is same but my alert message is not throwing

Any Idea why ?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire