Jump to content

Help needed posting data with jquery and updating a element


Dexlin

Recommended Posts

Hi everyone,

 

I would like to have a the comment system that i made submit the comment to the id on the current post( which works great), but i would like it to submit in the background using jquery. I have tried quiet a few answers i have found online but nothing works. Here is how my system works:

 

The page example.php?id=$id gets the post from the db

 

There is a form that show via a php function this form submits to postcomment.php (if the form is posted and the fields are not empty it say ok otherwise says Required fields can not be empty.

 

I have the id form for the form and id comments for comments list.

 

This is what jquery i have:

 

$(document).ready(function() {

$('#form').submit(function(e) {

	e.preventDefault();

	var url = $(this).attr('action');

	$.post(url, function(data) {
	if ( data = "Required fields can not be empty.") {
		alert("Required fields can not be empty.");
	}
	$('#comments').load();
	 });

});


});

 

When i submit the form with empty fields it alerts me with Required fields can not be empty. Great, but when entering the data in the fields the same message appears. So i dont know what i'm doing wrong.

 

Any help with this will be great.

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.