Jump to content

AJAX Success returning whole page html


Go to solution Solved by Adamhumbug,

Recommended Posts

Hi All,

I have an ajax call:

		var errors = [];

		var gv = $('#gameVenue').val();
		var ht = $('#homeTeam').find(":selected").val();
		var at = $('#awayTeam').find(":selected").val();
		if(gv == '') {
			$out = "Game Venue";
		if(ht == 0) {
			$out = "Home Team";
		if(at == 0) {
			$out = "Away Team";
		if(errors.length != 0){
			var finalArray = arrayToStringWithComma(errors)
			$('.newGameAlertContainer').html("<div class='alert alert-warning newGameAlert hiddenForFade'>"+finalArray+" must be completed!</div>")


		if (errors.length == 0){
				type: 'post',
				data: {'ajax': 'createNewgame', 'venue' : gv, 'home': ht,'away': at
				success: function(resp){
				error: function(XMLHttpRequest, textStatus, errorThrown) { 
					alert("Status: " + textStatus); alert("Error: " + errorThrown); 


then i have

		case 'createNewGame':
		exit(createNewGame($_POST['gv'], $_POST['ht'], $_POST['at']));

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!

Link to comment
Share on other sites

Join the conversation

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

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.