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..
- when i put it in an ascx and put the ascx out of
<form runat="server" >
...开发者_Python百科 tags it works - 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
精彩评论