Skip to content Skip to sidebar Skip to footer

Ajax Post Doesn't Send Data

I built a vote system with ajax and php, and I send data to php page for saved data in db. I tried to send data with ajax post and php. My problem is the data is not send to the pa

Solution 1:

Use post method. This is not the correct code, but it's an idea, always works for me.

$('.vote').click(function(){
//Your varsvar data='voteup';
//Your actions... ddClass/removeClass...
$.post('vote.php',data,function(data){
//On your vote.php use "if($data=='voteup') else ;"//And show message here...alert(data);
});
returnfalse;
});

example of vote.php

<?php$data=$_POST['data'];
if($data=='voteup')
echo"You voted up!";
elseecho"You voted down!";
?>

It's just an idea (:

Solution 2:

You can try changing this:

if (!parent.hasClass('.disabled')) {

to this:

if (!parent.hasClass('disabled')) {

Some Notes:

From the docs:

For $.ajaxSetup()

Description: Set default values for future Ajax requests. Its use is not recommended.

Solution 3:

Try using .post() function, you can set a callback when your action is done

jQuery.post(URL_TO_REACH, {ID_VALUE1 : 'my value' , ID_VALUE2 : 'my second value' })
                 .done(function( data_ajax ) {   // data_ajax : Your return value from your php scriptalert( data_ajax );
                 })
              });

Hope this will help you

Official documentation : http://api.jquery.com/jQuery.post/

Post a Comment for "Ajax Post Doesn't Send Data"