javascript - Ajax load issues with space in url -
i have 2 python files: gui.py & index.py
python.py contains table records mysql database.
gui.py contains python.py , textfield button send messages.
also, gui.py contains javascript load new python.py parameters.
gui.py script
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("#content").load("http://localhost/index.py"); $("button").click(function(){ var url = "http://localhost/index.py?name=1&message="; var msg = document.getelementbyid("message").value; var res = url.concat(msg); alert(res); //here can understand result url okay. $("#content").load(res); }); </script> and index.py part
cursor.execute("insert `messages` (`sender`, `receiver`, `text`, `time`) values ('" + req.form['name'] + "', '3', '" + req.form['message'] + "', now())") }); where req def index(req): i using mod_python.
so, problem is - when try send message space in - table disappears (till next page refresh (but don't need refresh without spaces, ajax load works here)). , see first word of message. can see in code, have alert(res); if copy alert , run url - spaces works nicely.
some details
i using ubuntu 14.04, apache2, mod_python, python 2.7, mysql database, python-mysqldb.
you should url encode message body protect against special characters in url, like, say, space. if did
var msg = encodeuricomponent( document.getelementbyid("message").value ); you may have better success.
Comments
Post a Comment