Sky Sky - 27 days ago 12
Ajax Question

Jquery $.ajax() $.post() why not work to append and request?

code by $.ajax()

$(function() {
$("#upgrade_id").keyup(function() {
var toid = $(this).val();
alert(toid);
$.ajax({
method: "POST",
url: "select.php?a=get_one_most",
data: { id = '1032' }

}).done(function( html ) {
$( "#upgrade_name" ).append( html );
});
});
});


code by $.post

$(function() {
$("#upgrade_id").keyup(function(){
var toid = $(this).val();
alert(toid);
$.post("select.php?a=get_one_most",{ name:toid },function(result){
$("#upgrade_name").html(result);
});
});
});


I need check a name on keyup();

if user enter a number on the input#upgrade_id,

I need to check this id name and append to input#updrade_name

But I had test $.ajax and $.post. I can't do it.

my php will be return a text only. I need it to input#updrade_name

I can't active the ajax function. but
alert(toid);
is work.

Answer

This is a syntax error:

data: { id = '1032' }

Change it to:

data: { id: '1032' }

And your full code would be:

$(function() {
  $("#upgrade_id").keyup(function() {
    var toid = $(this).val();
    alert(toid);
    $.ajax({
      method: "POST",
      url: "select.php?a=get_one_most",
      data: {
        id:'1032'
      }
    }).done(function( html ) {
      $( "#upgrade_name" ).append( html );
    });
  });
});