I want to pass data array ‘myWorkout’ to “play_workout.php”. I want “play_workout.php” to open and display the contents of ‘myWorkout’ (for this example). (Once I see that this is working I will parse the data from myWorkout and write it back to a database).
I’m not getting any errors in firebug, but play_workout.php is not being opened nor is it capturing array ‘myWorkout’.
Please advise if you’ve accomplished something like this. Thanks as always!
function playWorkout(){
var arr = $("#dropTargetframe > li").map(function(){
return $(this).attr('data-id');}).get();
var myRoutine = arr;
var myWorkout = new Array();
for (var i in myRoutine){
if (myRoutine[i])
myWorkout.push(myRoutine[i]);
}
//array appears like ["4", "5", "1", "4"]
JSON.stringify(myWorkout);
encodeURIComponent(myWorkout);
var url = "http://localhost/RealCardio/play_workout.php";
$.get(url, myWorkout);
It doesn’t because your understanding of what is supposed to happen is incorrect.
The web browser doesn’t navigate to the play_workout.php page. Instead, $.get() sends the data to the play_workout.php page, and the response from that page is passed back as data to a success function.
This example from the $.get() documentation page helps to demonstrate how it is used.
$.get("test.php", function (data) {
alert("Data Loaded: " + data);
});
If you want to leave page workout_now.php page and have a form submit its data so that the user end up at the play_workout.php page, you can do that with no scripting at all.
That makes perfect sense, but I’m using a javascript function playWorkout() to build an array of needed data.
The data needs to be passed to play_workout.php and then play_workout.php should be open to the user.