$ .ajax con GET

when we call $.ajax with GET method

$.ajax({
  type: "GET",
  url: "test.js",
  data: "id="+id
});

how to pass data to request file

is above given code is correct for that

preguntado el 02 de febrero de 12 a las 10:02

3 Respuestas

Your one is correct (but datano, dataType), tanto como

$.ajax({
  type: "GET",
  url: "test.js",
  data: {
      id: id
  }
});

is correct too

Respondido 02 Feb 12, 14:02

it was mistake in my post ...I also use data - Poonam Bhatt

@Matt: yep, realized that few moments after :-S - zerkms

The option to pass data as part of the request is called datano, dataType.

Have a read of the different options you can pass at: http://api.jquery.com/jQuery.ajax/

You can either craft the query/data string yourself, or let jQuery do it by just passing an object.

so your ajax signature should look something like this:

$.ajax({
  type: "GET",
  url: "test.js",
  data: "id="+id
});

or

$.ajax({
  type: "GET",
  url: "test.js",
  data: {
      id: id
  }
});

should both work

Respondido 02 Feb 12, 14:02


$.ajax({
  type: "GET",
  url: "test.js",
  data: "id="+id,   //not dataType  
  success: function(response) {
     //do osmething with response
  }
});


Respondido 02 Feb 12, 14:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.