English 中文(简体)
替换Ajax 电话
原标题:Replace Ajax Callback with Jquery callback
  • 时间:2012-05-11 06:10:47
  •  标签:
  • ajax
  • jquery

如何用jquery打背方法取代以下的麻风机?

function PostCall() {
  $( #txtRes ).val( Please Wait...... );
  var reqval = $( #txtReq ).val();
  $.ajax({
    url: "myPage",
    type:  post ,
    data: "{ name : " + reqval + " }",
    async: true,
    contentType: "application/json",
    success: function (result) {
      $( #txtRes ).val(result);
    }
  });
}
问题回答

仅对您的雅氏语句结尾处的成功表示(例如:

}.success(function(){
})

If you want to stick with Ajax go the jQuery 1.8 way and try this:

function PostCall() {
    $( #txtRes ).val( Please Wait...... );
    var reqval = $( #txtReq ).val();
    $.ajax({
        url:  myPage ,
        type:  post ,
        data: "{ name : " + reqval + " }",
        dataType:  json ,
        async: true,
        contentType: "application/json",
    })
    .done(function(result) {
        $( #txtRes ).val(result);
    })
    .fail(function(jqXhr, textStatus) {
        console.log( Error: ...  + textStatus);
    })
    .always(function() {
    });
}

<代码>.done()功能取代<>success。

If Ajax is not an option for you check out:

  • WebSockets
  • Http POST Requests (requires the whole page to be reloaded)




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签