Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To build on rayan.gigs and antyrat's answers, below is a fix to rayan.gigs answer and how you would receive that information on the controller side:</p> <p>rayan.gigs fixed answer (modified to match controller example below):</p> <pre><code>// your html &lt;script&gt; var myOrderString = "something"; $.ajax({ type: "POST", url: &lt;?= site_url('OrderController/receiveJavascriptVar'); ?&gt; data: {"myOrderString": myOrderString}, // fix: need to append your data to the call success: function (data) { } }); &lt;/script&gt; </code></pre> <p>The <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow noreferrer">jQuery AJAX docs</a> explain the different functions and parameters available to the AJAX function and I recommend reading it if you are not familiar with jQuery's AJAX functionality. Even if you don't need a success callback, you may still want to implement error so that you can retry the AJAX call, log the error, or notify the user if appropriate.</p> <p>antyrat (modified to fit controller example below):</p> <pre><code>&lt;form action="&lt;?= site_url('OrderController/receiveJavascriptVar'); ?&gt;" method="POST" id="myForm"&gt; &lt;input type="hidden" name="myOrderString" id="myOrderString"&gt; &lt;/form&gt; &lt;script&gt; var myOrderString = "something"; document.getElementById('myOrderString').value = myOrderString; document.getElementById('myForm'); &lt;/script&gt; </code></pre> <p>The controller could look like this for both of the above cases:</p> <pre><code>&lt;?php class OrderController extends CI_Controller { public function receiveJavascriptVar() { $myJSVar = $this-&gt;input-&gt;post('myOrderString'); // push to model } } ?&gt; </code></pre> <p>I would recommend rayan.gigs method instead of abusing forms. However, if you are trying to submit user information or submit information along side an existing form submission, you could use antyrat's method and just insert a hidden that you fill either on render, or via javascript.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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