- <form action="page_edit_save.php" method="post">
- <ul>
- <li>
- <textarea name="content" id="content" rows="15" cols="62">
- <?php get_page_content($id); ?>
- </textarea>
- </li>
- <li>
- <input type="hidden" name="id" id="id"
- value="<?php echo $id; ?>">
- <input type="submit" id="submit_page_edit"
- class="buttons" value="Edit page">
- </li>
- </ul>
- </form>
The page_edit_save.php pretty much looks like this:
- if(empty($_POST) === false) {
- $id = $_POST["id"]; $content = $_POST["content"];
- $return["msg"] = "Saving..."; edit_post($id, $content);
- $return["correct"] = "Yes";
- echo json_encode($return); exit(); }
- else {
- $return["msg"] = "Error. Please try again later.";
- echo json_encode($return); exit(); }
These two work good together and the database is updated as intended.
But when I try to include a .js file for some jQuery fun the database update fails.
The important parts of the .js code looks pretty much like this:
- $('#submit_page_edit').click(function(e) {
- e.preventDefault();
- var formData = $('form').serialize();
- submitForm_page_edit(formData);
- });
- function submitForm_page_edit(formData) {
- $.ajax({
- type: 'POST',
- url: 'page_edit_save.php',
- data: formData, dataType: 'json',
- cache: false,
- timeout: 7000,
- success: function(data) {
- $('#response').html(data.msg);
- $('#notification').css('visibility',
- 'visible').slideDown('fast');
- }
- });
- };
After much trying and failing I have found out that the .js-file doesn't seem get the data from the textarea.
Any clues on what I'm doing wrong?