Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>javascript on page: </p> <pre><code>function submitPostForm(url, data) { var form = document.createElement("form"); form.action = url; form.method = 'POST'; form.style.display = 'none'; //if (typeof data === 'object') {} for (var attr in data) { var param = document.createElement("input"); param.name = attr; param.value = data[attr]; param.type = 'hidden'; form.appendChild(param); } document.body.appendChild(form); form.submit(); } </code></pre> <p>after some event (like a click on "submit"):</p> <pre><code>// products is now filled with a json array var products = jQuery('#spreadSheetWidget').spreadsheet('getProducts'); var postData = { 'action': action, 'products': products } submitPostForm(jQuery('#submitURLcreateorder').val(), postData); </code></pre> <p>in the controller:</p> <pre><code> /** * @Route("/varelager/bestilling", name="_varelager_bestilling") * @Template() */ public function bestillingAction(Request $request) { $products = $request-&gt;request-&gt;get('products', null); // json-string $action = $request-&gt;request-&gt;get('action', null); return $this-&gt;render( 'VarelagerBundle:Varelager:bestilling.html.twig', array( 'postAction' =&gt; $action, 'products' =&gt; $products ) ); } </code></pre> <p>in the template (bestilling.html.twig in my case):</p> <pre><code> {% block resources %} {{ parent() }} &lt;script type="text/javascript"&gt; jQuery(function(){ //jQuery('#placeDateWidget').placedate(); {% autoescape false %} {% if products %} jQuery('#spreadSheetWidget').spreadsheet({ enable_listitem_amount: 1, products: {{products}} }); jQuery('#spreadSheetWidget').spreadsheet('sumQuantities'); {% endif %} {% endautoescape %} }); &lt;/script&gt; {% endblock %} </code></pre> <p>Alrite, I think that's what you wanted :)</p> <p><strong>EDIT</strong> To send something without simulating a form you can use jQuery.ajax(). Here is an example in the same spirit as above which will not trigger a page refresh.</p> <pre><code>jQuery.ajax({ url: jQuery('#submitURLsaveorder').val(), data: postData, success: function(returnedData, textStatus, jqXHR ){ jQuery('#spreadSheetWidget').spreadsheet('clear'); window.alert("Bestillingen ble lagret"); // consume returnedData here }, error: jQuery.varelager.ajaxError, // a method dataType: 'text', type: 'POST' }); </code></pre>
    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. This table or related slice is empty.
    1. VO
      singulars
      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