tags:

views:

50

answers:

2

How would you send long text from jquery to mysql becuase i have been trying use the .load function and for some reason i cannot get the text through.

 Var new_text = "oehieifewfewiofeio";
 $("#test").load("actions.php?act=save&new_text="+new_text);

Thank you,

+3  A: 

You should not normally save a string directly to a database from JQuery, which runs on the client. You should send it to the server-side code (PHP) first and then have the server save it to the database. You can do this using an AJAX call, for example.


Update after you described your problem in more detail

There are a couple of problems with your current approach. The msot serious problem is that URLs of over 2000 characters are a bad idea and will likely break. (Source)

Secondly from the documentation of .load:

The POST method is used if data is provided as an object; otherwise, GET is assumed.

You should use a POST instead of a GET if you are changing the state of the system.

Mark Byers
+2  A: 

I can provide you with the thought process behind posting data to your server via jQuery, but we're not going to write the code for you. You should attempt to implement this yourself and post specific questions you have if you encounter trouble.

You need two components:

  1. A client-side form with jQuery to accept input

  2. A server-side PHP script which accepts data and passes it to MySQL.

You can divide these components into two pages, one for outputting the HTML page for the client containing the form and JavaScript, and one for accepting the post data. Or, you can put both parts in a single page, and decide which action to perform based on the request method: GET serves up the page and POST accepts and inserts the data.

The flow of logic runs something like this:

  • User enters text in a form, and clicks "submit"
  • jQuery intercepts the form submit action, pulls the text from the field and sends it to your PHP script via $.post()
  • Your PHP script is invoked and accepts the data via $_POST
  • Your PHP script connects to the database and inserts the data

There are various additional niceities you can add, like displaying a loading spinner on your form until the postback is complete, and sending a response indicating success or failure from your PHP script back to the client.

meagar