Diferencia entre $ .getJSON () y $ .ajax () en jQuery
Estoy llamando a una acción MVC ASP.NET
public JsonResult GetPatient(string patientID)
{
...
desde JavaScript usando jQuery. La siguiente llamada funciona
$.getJSON(
'/Services/GetPatient',
{ patientID: "1" },
function(jsonData) {
alert(jsonData);
});
mientras que este no lo hace.
$.ajax({
type: 'POST',
url: '/Services/GetPatient',
data: { patientID: "1" },
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(jsonData) {
alert(jsonData);
},
error: function() {
alert('Error loading PatientID=' + id);
}
});
Ambos alcanzan el método de acción, pero el valor de ID de paciente es nulo con la llamada $ .ajax. Me gustaría usar la llamada $ .ajax para algunas de las devoluciones de llamada avanzadas.
Cualquier pensamiento apreciado.