JSON Callback not being called

The following code has worked in v1.3 but not 1.4 I can't seem to figure out what the issue is. I'm building a cities ddl from a selection from the province ddl. I'm using ASP.NET MVC 2

The function on the server gets called and it builds up the correct list, but when it returns it never steps into the callback function. I've put in some alerts, and the don't get called. except for the one before the getJSON

Anyone know what I'm doing wrong?

$(function () {

var provinces = $("#ProvinceId"); var cities = $("#CityId"); provinces.change(function () { cities.find('option').remove(); alert("hello outside JSON call"); $.getJSON('<%= Url.Content("~/HomeController/Cities") %>', { province: provinces.val(), includeAllPlaceholder : true }, function (data) { alert("hello"); $(data).each(function () { alert("hello 2"); $("<option value=" + this.Value + ">" + this.Text + "</option>").appendTo(cities); alert(this.Value + ":" + this.Text); }); }); });

});

in the controller

public JsonResult Cities(string province, bool includeAllPlaceholder) { List<SelectListItem> items = new List<SelectListItem>(); int provinceId; if (int.TryParse(province, out provinceId)) { var values = ReferenceTableService.CitiesInProvince(provinceId).Where(f => includeAllPlaceholder || (includeAllPlaceholder == false && f.IsAllPlaceholderEntry == false)).ToList(); values.Sort(); items.Add(new SelectListItem { Value = "", Text = Resources.Global.Generic.ddlSelectValue }); items.AddRange(values.Select(f => new SelectListItem { Value = f.Id.ToString(), Text = f.Name })); } return Json(items); }

thanks

TR

-------------Problems Reply------------

From api.jquery.com

Important: As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently. Avoid frequent hand-editing of JSON data for this reason. JSON is a data-interchange format with syntax rules that are stricter than those of JavaScript's object literal notation. For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes. For details on the JSON format, see http://json.org/.

thanks for all the help folks. turns out I needed to add in JsonRequestBehavior.AllowGet to my return statement

return Json(items); => return Json(items, JsonRequestBehavior.AllowGet);

*sigh

Category:jquery Views:0 Time:2011-09-19

Related post

  • Plurk API jSON Callback 2010-11-25

    Good Day! Who have tried Plurk API? I have a problem regarding JSON callback. I'm using $.getJSON by jquery to get public timeline of a user. The plurk supports JSON data. I need to implement JSONP for crossbrowsing problem, so i need to know the cal

  • Pass Parameters by Reference into AJAX JSON callback 2011-10-11

    Not quite sure how I pass a parameter by ref to a AJAX JSON callback C#.NET, e.g. if I have a web method like this: [WebMethod] public static string MyMethod(Int32 x, Int32 y, ref Int32 z) { z = x + y; return "Finished!"; } How do I set up the call b

  • Json callback problem 2010-08-24

    I'm trying to get a greasemonkey's script to work jquery and json. this is the json url http://www.sora101.net/auction.php?id=1&callback= this is part of the script $.getJSON("http://sora101.net/auction.php?id=1&callback=?", function(data){ a

  • Appending an extra request to JSON callback 2011-02-04

    My Problem I am trying to load JSON encoded data from a remote site using jQuery, however when jQuery tries to call this URL it appends the correct function to callback=? so it's something like callback=jsonp1256856769 but it also adds _=1256856769 t

  • jQuery: JSON callback function never reached 2011-03-09

    I'm requesting a page via JSON but never reach the callback-function. Does someone know why this is happening? jQuery.getJSON("'. $dnd_fileupload_dir .'dnd-medialink.php?format=json&jsoncallback=?", function(data){ alert("lalala"); }); ----------

  • Passing a variable to a jquery json callback 2011-04-14

    I am populating a list of (vehicle) models. If there is only one model available, I want to hide the model list. My initial problem is that (as expected) the getJSON is async. I then started looking for solutions along the lines of this ... but I can

  • Getting JSON callback not working 2011-07-07

    I want to use this api that returns the place matching a zipcode e.g. for zip 11233 http://postnummersok.se/api?q=11233 I call it with a user input value like this but the result does not parse, how can I troubleshoot, is it even getting the callback

  • Rails JSON callback - Sphinx 2011-12-01

    Im using thinking sphinx and it has become necessary to pull out the search results as JSON array with callback (JSONP). In my other functions like show, adding .json?callback=asd to the url allows this. But not for what i have retrieved with thinkin

  • json callback function not firing 2012-02-16

    this is my 1st post here :) As to my problem: I'm getting a (valid) JSON response from nominatim web server (also tested with jsonlint :) ) this is my code: ... google.maps.event.addListener(marker, 'click', function() { reverseGeoCodeNominatim (_lat

  • Javascript json callback 2012-03-29

    what does script.setAttribute('src', '/json?callback=loadJsonPhotos'); JavaScript code mean? --------------Solutions------------- That's a little snippet of code to set the src (source) attribute of a Javascript include tag to /json?callback=loadJson

  • Efficient way of populating 300+ DIVs with HTML data from a JSON callback? 2012-04-11

    I have a script that takes 18 seconds to complete because it's populating about 300 DIVs with HTML data. Code below: HTML: <div id="window"> <div id="wall"> <div class="module"> <div> <div class="face front"></div>

  • Using JSON callback in another function 2013-12-22

    I'm trying to use a getJSON result obtained in a function in another function, but I don't know how to do it, anyone can help me? I need to get text from an input and look in flickr for related images, later, I have to use that JSON call to take thos

  • jQuery JSON Callback says 'Undefined' 2010-08-24

    I'm creating this script which loads the data from JSON which is encoded in a PHP file (the JSON is valid). When a div is clicked on, it should show the data from the jQuery, which is done here: function quickView(pid) { $.getJSON('project.php', { id

  • JSON callback function only works with a text file 2011-03-09

    Does any one know why the call back only works with a text file PHP <?php include("alan.php"); ?> <?php $rows=array(); mysql_select_db('news') or die(mysql_error()); //echo "Connected to Database";<?php $result = mysql_query("SELECT * FRO

  • Google maps not mapping correct data with json callback on django 2011-06-28

    Trying to make use of jQuery getJson function to load some data to be displayed with Google Maps. I have a simple callback url for testing which is /projects/ajax_test/ when sending a AJAX get request I get the following data. [{"location_slug": "ber

  • is `this` invisible in a json callback? 2011-10-25

    the following JS code is being produced from CoffeeScript equivalent. I want to add objects to a slider widget, properties of these objects come from a Django REST view, nothing fancy, just a list of dictionaries. I am very new to both CoffeeScript a

  • parse json with a callback function in android 2011-07-21

    I am firing a request through my android application using HttpPost , as the request is returning a JSON Callback function , i don't know how to handle it and parse it. returned format: handleEmployeeResponse({ "records": [ { "fullDesc": "Records for

  • JSON editor/formatter? 2008-09-29

    I've got some JSON data, but it's all on one line. Does anyone know of a web or Windows editor that will format (e.g. indent and insert new lines) this data for me, so I can read it better? Preferably one that uses a GUI to display the JSON—instead o

  • Can I comment a JSON file? 2008-10-28

    Can I comment a JSON file? If so, how? --------------Solutions------------- I don't believe you can have an actual comment. The JSON should all be data, and if you include a comment, then it will be data too. You could have a designated data element

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.204 (s). 11 q(s)