Note that there are some explanatory texts on larger screens.

plurals
  1. POProcessing PHP variable in javascript and returning back to PHP
    text
    copied!<p>I am working on an application where I fetch data from database and process it using javascript/jquery like this:</p> <pre><code> $sqlEdit = "select revisionContent from tbl_revision where revisionId='".$_SESSION['contentId']."'"; //Query to fetch the result $rsEdit = $dbObj-&gt;tep_db_query($sqlEdit); $resEdit = $dbObj-&gt;getRecord($rsEdit); $IdLessContent = $resEdit['revisionContent']; &lt;script language="javascript"&gt; var getSavedContent = '&lt;?php echo json_encode($IdLessContent); ?&gt;'; var trimmedCont=($.trim(getSavedContent).slice(1)); //console.log(trimmedCont); var lengthCont= trimmedCont.length; var trimmedCont=$.trim(trimmedCont.slice(0,lengthCont-1)); console.log(trimmedCont); var test = $('&lt;div class="addId"&gt;'); test.append(trimmedCont); //console.log(test.html()); test.children().each(function(index, value) { $(this).attr('id', "com-"+randomString()); }); //console.log(test.html()); viewContent = test.html(); </code></pre> <p>I get the required data in <strong>viewContent</strong>.I want to display it on the page in this section</p> <pre><code> &lt;div id="mainWrap" onClick="fnDestroyEditable();"&gt; &lt;?php echo $resEdit['revisionContent']; ?&gt; //THis is the unprocessed data displayed directly from database.I want to display the processed data here &lt;/div&gt; </code></pre> <p>I know we cannot get javascript variables to PHP as both are different (<strong>one server side and other client</strong>). But then how can I achieve this in my scenario? <strong>EDIT</strong> I would like to add that the returned data is <strong>HTML</strong> stored in the database.So,I get the html->process it(add id attribute)-><strong>want to return back after processing</strong> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload