nullException
nullException

Reputation: 1122

jQuery Ajax success function parameters

  $.ajax({  
            type: "POST",  
            url: "contacts.php",  
            data: dataString,  
            cache: false,  
            success: function(data, status, settings)  
            {  
               alert(The request URL and DATA);
            }  
            ,
            error: function(ajaxrequest, ajaxOptions, thrownError)  
            {  

            }  
        });

How can I alert the The request URL and DATA parameters inside the Success function?

Thank You

Upvotes: 15

Views: 52893

Answers (3)

ricsdeol
ricsdeol

Reputation: 159

I needed return some data in sucess response like:

Action (Rais):

  def comment
    comnent = AlarmComment.new alarm_id: params[:id],
                user_id:  current_user.id, comment: params[:comment]

    if comnent.save
      render json: comnent, status: :created
    else
      head status: :unprocessable_entity
    end
  end

My Ajax (Coffee)

  $.ajax(
    url: "/alarms/#{alarm_id}/comment/"
    dataType: "json"
    method: "POST",
    data:
      comment: user_comment
  ).done( ->
    alert 'Comentário adicionado com sucesso'
  ).fail ->
    alert 'Erro ao adicionar'

Upvotes: 3

dieki
dieki

Reputation: 2475

Adapted from Alex K.'s answer, but using console.log instead:

success: function(data, textStatus, jqXHR)
{
   console.log(this.data + "," + this.url); 
}

This will output the data to the debugging console instead of a modal dialog.

Upvotes: 6

Alex K.
Alex K.

Reputation: 175758

You can simply;

success: function(data, textStatus, jqXHR)
{
   alert(this.data + "," + this.url); 
}

Upvotes: 29

Related Questions