jQuery $.post() doubt! -
I'm trying to use POST to pass the variable to try.htm in chat.php
The code for try.htm is:
& lt; Head & gt; & Lt; Script type = "text / javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> & Lt; Script type = "text / javascript" & gt; Function yo () {var text = $ ("# msg"). Val (); $ .post ("chat.php", message: text); } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Input type = "text" id = "msg" onkeyup = "yo ()" & gt; & Lt; Div id = "display" & gt; Change & lt; / Div & gt; & Lt; / Body & gt;
The code for .php is:
The problem is that the 'msg' variable does not seem to be passed on chat.php! What is wrong?
Change it to:
$ Post ("Chat.php", {msg: text});
jQuery is expected to pass as a data object and {...}
will essentially make an anonymous object for us msg : Lesson
- Without curly braces - unfortunately does not do much and will throw and throw at runtime.
By typing both of these together: {msg: text}
the value of your text
variable remains msg
Creates an anonymous object with a property of
Comments
Post a Comment