Ajax Not Working

Discussion in 'jQuery' started by jonathandey, Nov 4, 2010.

  1. #1
    Why is the following not posting successfully.

    
    function nogo(){
    		$.ajax({
    			var uid = <?= $user ?>;
    			var utype = <?= $type ?>
    			var anw = "no";
          		type: "POST",
          		url: "feedback.php",
          		data: "answer=" + anw + "&uid=" + uid + "&utype=" + utype,
          		success: function(returnValue){
          		alert(returnValue);
          		/*if(returnValue == 1){
          			$("div.question").fadeOut();
    				$("div.hidden").fadeIn().delay(2000);
          		}else{
          			$('div#date').fadeIn();
          		}*/	
          		}
       		});
    	}
    Code (markup):
    I think it has something to do with the data: part because when I change it to 1 value it works.
     
    jonathandey, Nov 4, 2010 IP
  2. jonathandey

    jonathandey Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Its not because I missed the semi-colon out here var utype = <?= $type ?> either.
     
    jonathandey, Nov 4, 2010 IP
  3. jonathandey

    jonathandey Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Silly my I was putting the variables in the ajax
     
    jonathandey, Nov 4, 2010 IP
  4. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #4
    if utype is a string then enclose it with quote

    
    var utype = "<?= $type ?>";
    
    Code (markup):
     
    gapz101, Nov 5, 2010 IP