php - Cannot pass $pdo as parameter in function triggered with onclick() -


i have html button has onclick method, triggers things happen ajax. variables passed through function, however, in php. here code:

html/php

#do not mind first forward slash# /<button type="submit"      name="follow_button"      onclick= <?php          echo "'follow_alert(" . $pdo . ", " . $_session['user_id'] . ", " . $value['user_id'].");'"          ?>  >follow </button> 

both variables $_session['user_id'] , $value['user_id'] passing fine. have tried code , works without $pdo, problem need $pdo called access in php function fetches data mysql table.

here js.

js

function follow_alert(pdo, user_id, following_id) {     var ajax = ajaxrequest();     ajax.onreadystatechange = function() {         if (ajax.readystate === 4) {             alert(ajax.responsetext);         };     };     ajax.open('get', 'function.php?pdo='+pdo+'&user_id='+user_id+'&following_id='+following_id, true);     ajax.send(null); }; 

my problem : keep getting "catchable fatal error : object of class pdo not converted string" error. when pass $pdo parameters in other functions, work fine. problem seems i'm passing through string run onclick(); @ least think is.

any thoughts? i've been wracking mind on morning!

you can’t pass resource, pdo instance, javascript function. doesn’t exist time html rendered. you’ll need create pdo instance in php script javascript function calls.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -