jquery $.post help

Associate
Joined
8 Mar 2007
Posts
2,176
Location
between here and there
hey guys,

I'm writing a web management tool and I'm having trouble sending the resutls of ckeditor to a php file on my server to be inserted in a database.

form which gets data from user;

Code:
<form name="page_editor" method="post">
    <textarea name="new_content"><?php echo $answer; ?></textarea>
		<script type="text/javascript">
            CKEDITOR.replace( 'new_content' );
        </script>
    <p align="left">
            	<input type="submit" value="  Save Changes  " onClick="save_page();" />
    </p>
</form>

javascript function
Code:
function save_page(){
	$.post('/site_admin/Scripts/edit_page.php', 
		   {new_content: CKEDITOR.instances.new_content.getData()},
		   function(data){
			   alert("Page Updated"); 
		   	   window.refresh;
			});
}

If i chuck in to a browser the full path of the edit_page.php (and hard code in the pagetoedit varabile) it works fine. putting in a black content page to my data base.

Also, If i change the alert box in my javascript function to ckeditor.instances.new_content.getdata() it returns everything in a popup box correctly.

It's almost as if the $.post doesn't fire the url off!

I've tried chnaging the $.post to $.get but get the same results.

I've got firebug installed, but I'm quite new to this web dev stuff so cant really follow what its doing once it dives into jquery.

I have just noticed that on the net tab of firebug, my post request shows as aborted! line reads ($POST edit_page.php status = aborted.)

Why would a post request get aborted like this?


Has anyone got any suggestions?

Does all my code above look ok?

I've edited my .htaccess to change the the domain url from domain.com to www.domain.com, would that be screwing around with the post function?

any help or suggestions as to whats not happening or hoe i can debug it further would be greatly apperciated.

thanks for your time,

blastman
 
Last edited:
Just use a normal ajax request with the value of the textarea being something like:

Code:
$('#textarea').val();

Then for your ajax request:

Code:
$.ajax({
data: $('#form').serialize(),
  url: 'ajax/test.php',
beforesend: function(data) {
    alert(data);
  }
  
success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});
 
Back
Top Bottom