开发者

jquery .net not firing the function $.ajax

开发者 https://www.devze.com 2022-12-29 04:58 出处:网络
im using jquery in asp.net, if i try to use $.ajax functionality, i got this if i use it in a separate page it works..

im using jquery in asp.net, if i try to use $.ajax functionality, i got this

  1. if i use it in a separate page it works..
  2. when i put it in an ascx and put the ascx out of <form runat="server" >...开发者_Python百科 tags it works
  3. if i put it between <form> tags , jquery works but it doesnt fire $.ajax event


In my experience most jQuery code should go in $(document).ready(), this is so that the DOM has loaded and the content is there, have you tried that? There is some good info on that here.

If that dosen't work, maybe post some code you are using?

HTH


ive solved it. the problem was with asp .net master pages, there are many ways of sending a post-get request from jquery in ajax, but it seems only some of them work in asp .net, ive posted the code for a chat control in c# in http://code.google.com/p/micachat/

an example that works for get request

$.ajax({
        beforeSend: function (XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Content-Type", "application/json");
         },
        type: "GET",
        url: "./chatControl/processmessage.aspx?idportal=<%=Request["idportal"] %>",
        data: "message=" + $('#message').val() + "&name=" + $('#name').val() + "",
        dataType: "text",
        success: function(msg){ $("#myDiv").text( "Data Received: " + msg ); }
        }); // end of ajax
0

精彩评论

暂无评论...
验证码 换一张
取 消