Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see nothing blatantly wrong with your code.</p> <p>If you are using a newer version of Jquery then I would suggest changing:</p> <pre><code>$("#category").change(function(){ </code></pre> <p>into</p> <pre><code>$("#category").on('change', function(){ </code></pre> <p>and certainly after</p> <pre><code>cache: false, </code></pre> <p>add</p> <pre><code>dataType: 'html', </code></pre> <p>Also I highly recommend using console.log()</p> <pre><code>if(data) { //check if expected data is correct console.log(data); //make sure you can target #mainview properly //should output the amount of #mainviews on your screen console.log($("#mainView").length); $("#mainView").html(data); $("#errorDivStyle").html("&lt;font color='#000000'&gt;" + category + " category have been loaded&lt;/font&gt;").show(); } </code></pre> <p>EDIT:</p> <pre><code> $("#category").on('change', function(){ e.preventDefault(); $.ajax({ type: "POST", url: "test.php", data: $(this).serialize(), cache: false, dataType: 'html', success: function(data) { if(data) { $("#mainView").html(data); $("#errorDivStyle").html("&lt;font color='#000000'&gt;" + category + " category have been loaded&lt;/font&gt;").show(); } } }); }); </code></pre> <p>Why were you returning FALSE anyways? I just realized that this is probably a text field change that you are listening for. So the e.preventDefault() isn't necessary either...</p> <p>Also if you just want to pass a single value to your test.php then you can try this:</p> <pre><code> $("#category").on('change', function(){ $.ajax({ url: "test.php?q="+$(this).val(), cache: false, dataType: 'html', success: function(data) { if(data) { $("#mainView").html(data); $("#errorDivStyle").html("&lt;font color='#000000'&gt;" + category + " category have been loaded&lt;/font&gt;").show(); } } }); }); </code></pre> <p>EDIT: recursively TRIM an array</p> <pre><code>/** * Returns a recursively TRIMMED variable * * @access public * @param mixed * @return mixed */ if ( ! function_exists('trim_r')) { function trim_r($var) { //In here you can add more code to handle objects properly but I did not because I am not using them with this function //if (is_array($var) || is_object($var)){some code} if (is_array($var)) { return array_map('trim_r', $var); } else { return trim($var); } } } // Usage examples $_POST = trim_r($_POST); $_GET = trim_r($_GET); $_REQUEST = trim_r($_REQUEST); $custom_array = trim_r($custom_array); </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. 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