douqiao7958
douqiao7958
2014-05-07 16:07

Jquery $ .get()和$ .ajax()没有得到相同的结果

I use the two different AJAX way to send/receive data from php file but can't get the same result

data.php

<?php
echo "hello";
?>

$.get()

if($(this).val() != '')
{
  $.get(
  'data.php',
  { what: $(this).val() },
  function(data)
  {
    $('#result').html(data);
    alert(data);
  });
}

$.ajax()

$('#choice').change(function()
{
  if($(this).val() != '')
  {
    $.ajax({type: GET, url: "data.php", complete: function(){alert("complete");}, success: function(data){alert(data);}, error: function(){alert("error");}});
});
}

.get() will return "hello" while .ajax() return nothing even no error.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • drwn65609 drwn65609 7年前

    You need to wrap GET inside quotes:

    type: "GET"
    
    点赞 评论 复制链接分享

为你推荐