php - jQuery AJAX method not working -
i'm going create page user can input in textarea (index.php). when user click on tweet, text user typed page tweet.php (i used jquery ajax method). after that, redirect page show.php
here code
index.php
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <title>tweet</title> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ function save_tweet(text_tweet){ $.ajax ({ type: "post", url: "tweet.php", data: "text="+text_tweet, success: function(msg) { if(msg==1){ window.location.href="show.php"; }else{ alert("error"); } } }); } $("#tweet").bind('click', function(){ var text_tweet = $("#text_tweet").val(); if(text_tweet==""){ $("#show").html("blank text"); return; }else{ $("#show").html(""); save_tweet(text_tweet); } }); }); </script> </head> <body> <center> <textarea name="text_tweet" cols="61" rows="5" id="text_tweet"></textarea> <br/> <div id="show"></div> <br/> <a href="#" id="tweet">tweet</a> </center> </body> </html>
tweet.php
<?php session_start(); if(isset($_post['text'])){ $_session['text_tweet'] = $_post['text']; } ?>
show.php
<?php session_start(); echo $_session['text_tweet']; ?>
the problem when input text in textarea , click tweet, alert error. can know problem?
thank in advance.
why checking if msg 1 ? returning 1 in response body ? looking @ jquery docs success function callback described as:
type: function( plainobject data, string textstatus, jqxhr jqxhr )
you log value of msg , see contains.
Comments
Post a Comment