so I'm writing this form for teams and doing this 'add player' function where you enter a player name in a textfield, check a box for medically ok and click a button which then appends the name to a div above, adds the value to an array and clears the textfield below, like so:

<script>
     var players = New Array();
     function addPlayer(){
          $('#players').append($('#addPlayerField').val());
          var playerInfo = New Array($('#addTermCheckbox').prop('checked'),$('#addPlayersField').val());
          addingTerms.push(playerInfo);
          $('#addPlayerField').val('');
       }
</script>

Whats the best way to post the final array to a php script?

Thanks guys!

有帮助吗?

解决方案

I would use JQuery's ajax method:

$.ajax({
  type: 'POST',
  url: url,
  data: 'players='+$.toJSON(players),
  success: function (data) {}
});

http://api.jquery.com/jQuery.post/

其他提示

What do you meen with posting the final array to a php script? If you want to send the information to a php script try looking the jquery documentation about ajax (to send the data to the php file without reloading the page) and json (to convert your array into a text form and then beeing able to rebuild the array in the php file)

Do you mean sending the array elements to a PHP script? in JSON and use json_decode() in PHP. Depending on what information you need, json_decode() can either convert to an associate array, or objects. Use JQuery-Json which will add the ability to encode JSON in your code.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top