How to send data from browser to server and reply back
NickName:Cristian Calu Ask DateTime:2011-09-18T15:17:27

How to send data from browser to server and reply back

On my webpage I have a textarea where the user inputs all kind of characters.
When he saves it I want to send the data using AJAX to the server for storing in the database. After this, the server will send back the data to the browser to be displayed.

Which is the right way to do this?
Right now I make an AJAX call:

function update()
{
    $.ajax({
        type: "POST",
        url: "ajax/update.php",
        data: "ID=" + ID + "&value=" + encodeURIComponent($('#newText').val()),
        success: function(html) {
            $('#l' + CurrentID).html(decodeURIComponent(html));
        }
    });
}

and my php file looks like this:

<?php

$ID = $_POST["ID"];
$value = nl2br(urldecode($_POST["value"]));
if (get_magic_quotes_gpc()) {
    $value = stripslashes($value);
}
$value = htmlentities($value);

$value = str_replace("<br />", "", $value);
$value = str_replace("<br/>", "", $value);
$value = str_replace("<br>", "", $value);

mysql_query("update MyTable set value = '$value' where id = $ID");

echo html_entity_decode(urlencode($value));
?>

I am not sure I am doing the things right. For sure I can see now the problem with spaces being replaced by + sign. But I am thinking that there is something I am not doing it by the book.

Copyright Notice:Content Author:「Cristian Calu」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7460068/how-to-send-data-from-browser-to-server-and-reply-back

More about “How to send data from browser to server and reply back” related questions

How to send data from browser to server and reply back

On my webpage I have a textarea where the user inputs all kind of characters. When he saves it I want to send the data using AJAX to the server for storing in the database. After this, the server w...

Show Detail

How to send URL back as reply by web server in python

I have written this HTTP web server in python which simply sends reply "Website Coming Soon!" to the browser/client, but I want that this web server should sends back the URL given by the client, l...

Show Detail

Send Reply to email thread

I'm trying to reply to an email based on the following criteria: Scan the inbox for unseen mails with specific Subject content, if there is mails that satisfy those criteria then: send back an reply

Show Detail

How could I ask browser to send back a header field from server side?

Now I am working on a project in which I send X-Request-Id header to browser client. And now I want browser client side send this field back to my server side. How could I implement this? As now, ...

Show Detail

Reply back to a response

I need to reply back to a response received. How should I reply using the response? I want to reply to a response received in my MDM System. The device contacts the server and delivers status as ...

Show Detail

how to create a server which can reply to a SMS from cell phone and search relevant information back to that number?

i want to develop a system in which we can store our passwords of different accounts or ATM etc thought a website in a database (cell number will be the primary key)to a server. this information ne...

Show Detail

How do I send data back to the browser from the server?

I have a form on a webpage that asks for the client's username, password, age, and gender. I submit it to the nodejs server (express framework) when the user clicks the submit button. I want to que...

Show Detail

How to send back data automatically from a server back to the client and display it?

So I have this "client" PHP page, and a "server" PHP page. And I'm trying to send a value from the client to the server using the GET-method. And then I want to send the information back again from...

Show Detail

How to send-back some data from server to browser with fetch API's response body

onclick function for a HTML5 button is implemented like below, to send some data to server with fetch API. But I want to be able to receive data from server's response body. How can I do that: fun...

Show Detail

How can I send a URL from the browser to a server to be scraped while using React?

To avoid CORS errors when attempting to scrape from inside the browser, I want to hold a scraper inside a server. How can I send a URL generated in the browser to a server, have the server scrape and

Show Detail