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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.