php - jQuery, JavaScript - Network Error? -
i working on building javascript/jquery , ajax website. however, while testing encountering following error:
timestamp: 6/11/2016 10:13:45 error: networkerror: network error occurred.
to me, obvious culprit ajax call made in script; however, tried commenting out , still received same error. when website first loaded displays 3 alert boxes (selection=category&detail=test, , on), error appears , changing selection not trigger alert.
here main page:
<?php include('header.php'); ?> <div id='maincontent'> <?php /* if(!$_session['admin']) { echo "<p>you not have permission view page!</p>"; } else { */ echo "<form method='post' action='additem.php'> <div class='form-group'> <label>category</label> <select id='categoryselection' name='categoryselection'> <option value=1>playstation</option> <option value=2>wii</option> <option value=3>gamecube</option> <option value=4>n64</option> <option value=5>other console</option> <option value=6>ds</option> <option value=7>game boy</option> <option value=8>other handheld</option> <option value=9>dvd</option> </select> </div> <div class='form-group'> <label>item</label> <select id='itemselection' name='itemselection'> </select> </div> <div class='form-group'> <label>condition:</label> <select id='conditionselection' name='conditionselection'> <option value=1>acceptable</option> <option value=2>good</option> <option value=3>very good</option> <option value=4>new</option> </select> </div> <div class='form-group'> <label>price: </label> <input id='itemprice' type='text' name='itemprice' /> </div> <div class='form-group'> <label>description: </label> <textarea id='itemdescription' name='itemdescription'></textarea> </div> </form>"; // } ?> </div> <script> function selectionhandler(selectedaction, selectedvalue) { var gamedata = "selection=" + selectedaction + "&detail=" + selectedvalue; alert(gamedata); $.ajax({ type: 'post', url: 'filter.php', data: gamedata, success: function(returndata) { if(selectedaction == 'category') { $('#itemselection').html(returndata); } if(selectedaction == 'game') { $('#itemprice').val(returndata) } else { $('itemdescription').val(returndata); } } // end return }); // end ajax } // end handler $(document).ready(function() { $("#categoryselection").on("change", selectionhandler('category', "test" ) ) ; $("#itemselection").on('change', selectionhandler('game', "test" ) ); $("#conditionselection").on('change', selectionhandler('condition', "test" ) ); }); // end ready </script> <?php include('footer.php'); ?>
and php
<?php include("header.php"); $db = new pdoaccess("localhost","root",""); $selection = $_post['selection']; // either game, category, or condition $detail = $_post['detail'] // either categoryid or isbn/item id if($selection == 'category') { $products = $db->filterbycategory($detail); $html = ""; foreach($products $product) { $html += "<option value={$product->upc)}>$product->title</option>"; } return $html; } elseif ($selection = 'game') { return $db->getproductprice($detail); } else { return $db->getcategorydescription($detail); } ?>
thanks!
edit: should noted tried other events such focusout , select. same issue.
in php string cocatinating dot .
, use quotes change here this
$html .= "<option value='{$product->upc)}'>{$product->title}</option>";
also use double ==
compare here
} else if ($selection == 'game') {
use echo in ajax instead of return
Comments
Post a Comment