Reputation: 2975
I want to use jQuery to make a simple call to my MVC controller. I was able to debug the server side, meaning the controller picked up the ajax call and return the information requested. But the client side is never updated after server side returns. When I use FireBug to debug the script, the client side is stuck on event.isImmediatePropagationStopped() in handle() of jquery-1.4.1.js. Does that mean the client side simply didn't get called back? Please help.
$('#ToZip').blur(function() {
$.getJSON('http://localhost:3958/home/GetZipInfo?id=' + this.value,
function(result){
$("#ToCity").val = result.City;
$("#ToState").val = result.State;
}
)
});
public ActionResult GetZipInfo(string id)
{
// some code to prepare return value, zip
return Json(zip, JsonRequestBehavior.AllowGet);
}
Thanks in advance
Upvotes: 2
Views: 5391
Reputation: 1
If your using ASP.Net MVC 3 then try with this.
$('#btnGetProduct').click(function () {
$.getJSON("/Home/getproduct", { code: tcode.value }, function (data) {
$('#tname').val(data.Pr_Name);
});
});
Upvotes: 0
Reputation: 2282
If your using ASP.NET MVC 2.0 then try using a "POST" versus "GET" on the method something like;
$.ajax({
type: 'POST',
url: 'http://localhost:3958/home/GetZipInfo',
data: {id: this.value },
success: function(data) {
$("#ToCity").val = data.City;
$("#ToState").val = data.State;
}
dataType: "json"
});
Upvotes: 0
Reputation: 1
try this way,
var ID = $('#ToZip').val();
var url = '<%= Url.Content("~/") %>' + "home/GetZipInfo";
$.getJSON( url, { id: ID }, function(result){ $("#ToCity").val = result.City; $("#ToState").val = result.State; } );
Upvotes: 0
Reputation: 6838
Have you validated your json response? http://api.jquery.com/jQuery.getJSON/ states:
As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently.
Open you handler directly in a browser, and copy and paste it in here: http://www.jsonlint.com/
Upvotes: 3
Reputation: 78667
I think it maybe because your using a full url "http://localhost:3958/home" - jquery might think your going cross domain so attempts a jsonp call. An easy way to check in firebug is to see if a script was requested or an xhr call attempted, a jsonp call also appends a callback parameter to the querystring.
Try changing the url to just '/home/GetZipInfo?id=' + this.value
Upvotes: 0