Ajax load issues with space in url

0 votes

I have 2 python files: gui.py & index.py

python.py contains table with records from mysql database.

gui.py contains python.py and textfield with button to send messages.

Also, gui.py contains javascript that will load new python.py with 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 I always can understand that result URL is okay.
        $("#content").load(res);
    });
</script>

And index.py part

cursor.execute("INSERT INTO `messages` (`sender`, `receiver`, `text`, `time`) VALUES ('" + req.form['name'] + "', '3', '" + req.form['message'] + "', now())")
});

Where req is from def index(req): I am using mod_python.

So, the problem is - when i try to send message with space is in - my table disappears (till next page refresh (but i don't need to refresh it without spaces, ajax load works good here)). And then I will see only the first word of the message. As you can see in my code, i have alert(res); if I copy that alert and just run that url - spaces works nicely.

Some details

I am using ubuntu 14.04, apache2, mod_python, python 2.7, mysql database, python-MySQLdb.

May 27 in JQuery by Edureka
• 13,600 points
59 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In JQuery

0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello, Here is the syntax using jQuery $.get $.get(url, data, ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,720 points
23,712 views
0 votes
1 answer

How can I select an element with multiple classes in jQuery?

Hello @kartik, If you want to match only ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,720 points
1,214 views
0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello @kartik, Use data option of ajax. You ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,720 points
2,473 views
0 votes
1 answer

How to find a parent with a known class in jQuery?

Hello @kartik, Assuming that this is .d, you can write $(this).closest('.a'); The closest method returns the ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,720 points
1,834 views
0 votes
1 answer

What is the difference between AJAX with JavaScript and jQuery?

JavaScript is a programming language. JQuery is ...READ MORE

answered May 30 in JQuery by gaurav
• 12,500 points
19 views
0 votes
1 answer

jQuery find all elements with class beneath parent, even in children elements

Remove > from your select $(".parent .searchEl"). You can use the .find() method ...READ MORE

answered Jun 7 in JQuery by Edureka
• 13,600 points
9 views
0 votes
1 answer

Show Page Loading Spinner on Ajax Call in jQuery Mobile

 Use the ajaxStart() and ajaxStop() Method While working ...READ MORE

answered Jun 10 in JQuery by gaurav
• 12,500 points
14 views
0 votes
1 answer

Ajax using JQuery in ASP .NET c#

jQuery Ajax in ASP.Net $.ajax({      & ...READ MORE

answered Jun 15 in JQuery by rajatha
• 3,540 points
8 views
0 votes
1 answer

How to shorten repeating code with html function and return tags in jquery

Firstly note that replace() only accepts two arguments, the ...READ MORE

answered Jun 15 in JQuery by rajatha
• 3,540 points
6 views
0 votes
1 answer

Ajax load issues with space in url

You should URL encode the message body ...READ MORE

answered Jun 1 in JQuery by Edureka
• 13,600 points
19 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP