Skip to main content

The json encode did not return response after calling the function of fb post to wall



I have a link which posted data to another page vote.php through jquery.





When I click on that link, it return the state according to the condition. If that user posted the vote before then it displayed the "already voted" other wise "Your vote posted".





All was working fine.





I am using the facebook post to wall sdk.





Now when I call the fb_publish_on_wall function from the vote.php, the message successfully posted to my fb wall but it did not return the state of the vote like "Your vote posted".





What is the problem. When I comment out that line where I am calling the fb_publish_on_wall function then It works fine.





I think the jquery did not get response from vote.php after calling the fb_publish_on_wall function.





How will I fix this?





UPDATED: Here is the fb_publish_on_wall function







function fb_publish_on_wall($message,$link,$picture,$name,$description,$user_facebook2)

{

$message = str_replace(array('<br />', '<br>'), "\n", $message);

$description = str_replace(array('<br />', '<br>'), "\n", $description);

$name = str_replace(array('<br />', '<br>'),"\n", $name);

$link = str_replace(array('<br />', '<br>'), "\n", $link);



global $facebook;



$publishStream = $facebook->api("/$user_facebook2/feed", 'post', array(

'message' => "$message",

'link' => "$link",

'picture' => "$picture",

'name' => "$name",

'description'=> "$description"

));



print $user_facebook2;







}







UPDATED: vote.php. This file is big. SO I am only displaying the that two lines from vote.php







echo json_encode(array("state"=>"<span style='color:#8DA326'>".l("Your vote posted").".</span>"));



fb_publish_on_wall($message,$link,$picture,$name,$description,$user_facebook2);




Comments

  1. Remove the print statement in fb_publish_on_wall function, as that will also be part of the return value and will interfere with the json_encoded return value you parse in jquery.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.