Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To answer your main questrion, just add your GET parameters to the end of the URL that you are calling in the ajax call. Something along the lines of:</p> <pre><code>$.ajax({ type: "GET", // the kind of data we are sending url: "troncare.php?troncami=" + $('#troncami').val(), // this is the file that processes the form data success: function(msg){ // anything in this function runs when the data has been successfully processed // this sets up our notification area for error / success messages $("#risultatotroncato").ajaxComplete(function(event, request, settings) { result = msg; // msg is defined in sendmail.php $(this).html(result); // display the messages in the #note DIV }); $('#troncami').val(msg); } }); </code></pre> <p>Or you can use the <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow noreferrer">data setting</a> of the $.ajax call to pass in key/value pairs:</p> <pre><code>$.ajax({ type: "GET", // the kind of data we are sending url: "troncare.php", // this is the file that processes the form data data: {"troncami" : $('#troncami').val()}, // this is our serialized data from the form success: function(msg){ // anything in this function runs when the data has been successfully processed // this sets up our notification area for error / success messages $("#risultatotroncato").ajaxComplete(function(event, request, settings) { result = msg; // msg is defined in sendmail.php $(this).html(result); // display the messages in the #note DIV }); $('#troncami').val(msg); } }); </code></pre> <p>Notice that I used '#troncami' instead of 'input[name=troncami]' as the selector for the input. While it might seem trivial, on a large scale it is <a href="http://24ways.org/2011/your-jquery-now-with-less-suck" rel="nofollow noreferrer">much more efficient</a> to use the ID of an element as a selector than to use a filter style selector. An ID should be unique in a page so the object is found quickly in the DOM. If you use a filter style selector (like 'input[name=troncami]') the object has to first be found. You should also consider investigating using callback parameters on Ajax/JSon calls as these can help with avoiding cross site scripting (XSS).</p> <p>On another note I hope that you will do some data validation and cleansing on the receiving end of the ajax call. As your code is now it is wide open to injection attacks. At the very least in your case I would use something like this in troncare.php to validate the input value before querying or inserting into the database:</p> <pre><code>&lt;?php $risultatotroncato = 0; if (isset($_GET['troncami']) &amp;&amp; ctype_digit($_GET['troncami'])) { $risultatotroncato = substr ($_GET['troncami'],0,4); //echo or search the database here } else { //do whatever here if the value is blank or contains invalid characters } ?&gt; </code></pre> <p>That ensures that the value received can only be numbers (1234567890).</p> <p><strong>UPDATE:</strong> If I undertsand your situation correctly in this instance the value that should be received by troncare.php should always be only numbers if it is valid so the PHP function <a href="http://php.net/manual/en/function.ctype-digit.php" rel="nofollow noreferrer">ctype_digit()</a> will be enough to cleanse the data and will only return true if the value contains only numbers. That is enough of a cleanse <strong>in this situation</strong>. If you were allowing letters or numbers there are several other <a href="http://php.net/manual/en/ref.ctype.php" rel="nofollow noreferrer">ctype functions</a> that can help. If the data is of a non standard type you can use a preg_match which uses pattern matching. In all other situations there is normally a PHP function that matches your database type for cleansing data. Like for example if you are using MySQL there is a PHP function called mysqli_real_escape_string(), and mysql_real_escape_string() which cleanses data before using it in any way with the database. I won't re-invent the wheel in this department but there are many good questions on SO (and elsewhere on the web) that deal with this topic for example: <a href="https://stackoverflow.com/questions/129677/whats-the-best-method-for-sanitizing-user-input-with-php">here</a></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. 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