Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.