Adamhumbug Posted December 31, 2021 Share Posted December 31, 2021 Hi All, I have an ajax call: $('#createNewgame').click(function(){ var errors = []; var gv = $('#gameVenue').val(); var ht = $('#homeTeam').find(":selected").val(); var at = $('#awayTeam').find(":selected").val(); if(gv == '') { $out = "Game Venue"; errors.push($out); } if(ht == 0) { $out = "Home Team"; errors.push($out); } if(at == 0) { $out = "Away Team"; errors.push($out); } if(errors.length != 0){ var finalArray = arrayToStringWithComma(errors) $('.newGameAlertContainer').html("<div class='alert alert-warning newGameAlert hiddenForFade'>"+finalArray+" must be completed!</div>") $('.newGameAlert').fadeIn().delay(3000).fadeOut(1000); return; } if (errors.length == 0){ $.ajax({ type: 'post', data: {'ajax': 'createNewgame', 'venue' : gv, 'home': ht,'away': at }, success: function(resp){ console.log(resp) }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("Status: " + textStatus); alert("Error: " + errorThrown); } }) } }) then i have if(isset($_POST['ajax'])){ switch($_POST['ajax']){ case 'createNewGame': exit(createNewGame($_POST['gv'], $_POST['ht'], $_POST['at'])); break; } } function createNewGame($venue, $home, $away){ include 'includes/dbconn.php'; $qry = "INSERT INTO game (venue, home_team, away_team) VALUES (?,?,?)"; $stmt = $conn -> prepare($qry); $stmt -> bind_param('sii', $venue, $home, $away); $stmt -> execute(); $gameID = mysqli_insert_id(); $_SESSION['activeGame'] = $gameID; return "i ran"; } the success response that i am console logging is the entire html of the whole page. All of this code appears in the same file. Any ideas or pointers? All help appreciated, and have a great new year! Quote Link to comment https://forums.phpfreaks.com/topic/314375-ajax-success-returning-whole-page-html/ Share on other sites More sharing options...
Solution Adamhumbug Posted December 31, 2021 Author Solution Share Posted December 31, 2021 Turned out to be a miss-capitalised bit of data 37 minutes ago, Adamhumbug said: data: {'ajax': 'createNewgame', 'venue' : gv, 'home': ht,'away': at createNewgame should have been createNewGame Sorry all. Thanks for looking anyway. Quote Link to comment https://forums.phpfreaks.com/topic/314375-ajax-success-returning-whole-page-html/#findComment-1593102 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.