Carlos Carlos - 1 year ago 76
jQuery Question

MVC AJAX QUERY Callback not working

Im trying to make a simple Jquery Ajax callback:

This is my Jquery code:

$(document).ready(function () {
$('#btnClient').click(function (e) {
var txtClient1 = $('#txtClient').val();

type: "POST",
url: '/VistasController/AROrders',
contentType: "application/json; charset=utf-8",
data: { txtClient: txtClient1},
dataType: "json",
success: successFunc,
error: errorFunc

function successFunc(data) {

function errorFunc(result) {
alert("Error" + result.responseText);

This is my c# code behind:

public ActionResult AROrders(string txtClient)
DataTable dtClients = clientData(txtClient);

System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dtClientes.Rows)
row = new Dictionary<string, object>();
foreach (DataColumn col in dtClients.Columns)
row.Add(col.ColumnName, dr[col]);
string ResultadoJSON = serializer.Serialize(rows);

return this.Content(ResultadoJSON, "application/json");


When I do a normal postback it works but with Jquery I get the error "Resource not found"

I have tried configuring the route in global.asax

new { controller = "Vistas", action = "AROrders", txtClient = UrlParameter.Optional }

I have also tried changing the URL without success.

Is there anything wrong with the Jquery?

Answer Source

Dont specify the postfix Controller in your URL. So instead of :

url: '/VistasController/AROrders',

chnage it to

url: '/Vistas/AROrders',