Luis Molina
Luis Molina

Reputation: 577

jquery .net not firing the function $.ajax

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" >... tags it works
  3. if i put it between <form> tags , jquery works but it doesnt fire $.ajax event

Upvotes: 0

Views: 115

Answers (2)

Luis Molina
Luis Molina

Reputation: 577

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

Upvotes: 0

DannyLane
DannyLane

Reputation: 2096

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

Upvotes: 1

Related Questions