Destramic Posted November 20, 2011 Share Posted November 20, 2011 hey guys im having a problem with the ajax sctipt...basically when i used selects an option in the game_platforms i want the ajax to then work when the json is encoded....help please...i dont know why it aint running the code is below...thank you guys php getting the array if (!empty($_POST['game_platform'])) { $game_platform_value = $_POST['game_platform']; $platform_games_rows = $game_platform->select_platform_games($game_platform_value); json_encode($platform_games_rows); } ajax....not working $(document).ready(function() var post_string = 'game_platform=' + $(this).val(); $.ajax ({type: 'POST', data: post_string, cache: false, dataType: 'json', url: 'add_league.html', timeout: '2000', error: function(data) { console.log(data); }, success: function(data) { alert('yes'); } }); }); the html form <form method="post"> <input type="hidden" name="game_add" value="0" /> <label for="league_name">League Name:</label> <input type="input" name="league_name" id="league_name" /> <br /> <label for="league_size">League Size:</label> <input type="input" name="league_size" id="league_size" /> <br /> <label for="league_status">League Status:</label> <select id="league_status"> <option>Active</option> <option>Inactive</option> </select> <label for="game_platform">Game Platform:</label> <select name="game_platform" id="game_platform"> <option value=""></option> <option value="<br /> <b>Notice</b>: Undefined index: platform_abbreviated in <b>C:\www\private\application\views\leagues\add_league.html</b> on line <b>108</b><br /> ">Play Station 2</option> </select> <br /> <div id="create_game_expanded"> <div id="create_game_collapse">Select existing game</div> <br /> <label for="game_name">Game Name:</label> <input type="input" name="game_name" id="game_name" /> <br /> <label for="game_name_abbreviated">Game Name Abbreviated:</label> <input type="input" name="game_name_abbreviated" id="game_name_abbreviated" /> <br /> <label for="game_icon">Game Icon:</label> <input type="file" name="game_icon" id="game_icon" /> <br /> <label for="game_type">Game Type:</label> <input type="input" name="game_type" id="game_type" /> <br /> <label for="game_type_abbreviated">Game Type Abbreviated:</label> <input type="input" name="game_type_abbreviated" id="game_type_abbreviated" /> <br /> </div> <div id="create_game_collapsed"> <div id="create_game_expand">Create game</div> <br /> </div> </form> Link to comment https://forums.phpfreaks.com/topic/251484-ajax-json-help/ Share on other sites More sharing options...
trq Posted November 20, 2011 Share Posted November 20, 2011 when i used selects an option in the game_platforms i want the ajax to then work then you need to attach a 'change' event to your dropdown that triggers the Ajax request. Link to comment https://forums.phpfreaks.com/topic/251484-ajax-json-help/#findComment-1289856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.