ajax request +response +jquery

Discussion in 'PHP' started by vetrivel, Jul 8, 2009.

  1. #1
    Hi ,
    Please tell me how to call the ajax request and add a response into DIV.

    This is what i tried:

    $.ajax({
    type: "POST",
    url: "test.php",
    data: "username=vetri",
    success: function(msg){
    $("#loggedin").html(msg);

    }
    });

    And also in the php file i have added a few redirection and when i call the ajax without using jquery it didnt redirect but when using jquery it is making a extra ajax request for that redirect url.(i have found this in the firebug).

    How to solve this.
    I dont like to redirect that url only when i made a ajax call.

    Please guide me.
     
    vetrivel, Jul 8, 2009 IP
  2. DimitryKislichenko

    DimitryKislichenko Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi, vetrivel

    If you want just to make ajax request and load response into div you can use this function:

    jQuery.post(url, [data], [callback], [type])
    Code (markup):
    Example:

    jQuery.post("test.php", { username: "vetri" }, function(data) {
       $("#loggedin").html(data);
    }, "html");
    Code (markup):
    But if there are redirects in your test.php, I think that it will not work.
     
    DimitryKislichenko, Jul 8, 2009 IP
  3. vetrivel

    vetrivel Peon

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I need to handle the error and success handle,because the when this request succeed than i need to call another request.
    chain process.

    But it worked in the simple ajax call(without using any plugins).
     
    vetrivel, Jul 8, 2009 IP