Tag: json

jqGrid-> treeGrid不能与我的angular指令一起使用

我正在使用JqGrid和angularJS的指令。 例如,我正在使用来自此jqgrid的代码从服务器加载json数据到treegrid不显示数据 这是指令: .directive(‘ngJqGrid’, function () { return { restrict: ‘E’, scope: { config: ‘=’, data: ‘=’, }, link: function (scope, element, attrs) { var table; scope.$watch(‘config’, function (newValue) { element.children().empty(); table = angular.element(”); element.append(table); $(table).jqGrid(newValue); }); scope.$watch(‘data’, function (newValue, oldValue) { var i; for (i = oldValue.length – 1; i >= 0; i–) { […]

将JSON传递给JQuery函数Javascript

我们有一个非常简单的Google Apps脚本Web应用程序,其目的是在HTML下拉列表中显示JSON数据。 JSON文件存在于Google云端硬盘中。 灵感代码来自: http : //jsfiddle.net/manoj_admlab/Mta5b/3/ 但是当我们尝试“获取Json”时,没有数据被加载到下拉列表中: 的index.html Select Fetch JSON google.script.run.getJson(); // Runs the function “getJson();” in Code.gs $(‘#fetch’).click(function(s) { $.post(s, {json: JSON.stringify(json)}, function(data) { $.each(data.Destinations, function(i, v) { $(‘#destinations’).append(” + v.destinationName + ”); }); }); }); Code.gs function doGet() { var template = HtmlService.createTemplateFromFile(‘index’); var htmlOutput = template.evaluate() .setSandboxMode(HtmlService.SandboxMode.NATIVE); return htmlOutput; } […]

ajax回发不正常

更新的问题 最近我需要在ASP.NET MVC 3中实现一个多步骤向导。经过一些研究,我能够找到这个解决方案。 http://afana.me/post/create-wizard-in-aspnet-mvc-3.aspx 所以除了下面列出的小改动之外,我完全按照它的例子进行操作: @using (Html.BeginForm()) { @Html.ValidationSummary(true) User @Html.Partial(“UserInfo”, this.Model) @Html.Partial(“Email”, this.Model) @Html.Partial(“Cars”, this.Model) <input type="button" id="back-step" name="back-step" value=" ” /> } 如您所见,我正在使用部分视图来呈现每个步骤。 然后我继续创建一个将用于此视图的ViewModel: public class UserViewModel { public UserViewModel() { } [Required(ErrorMessage=”Username”)] public string UserName { get; set; } public string FirstName { get; set; } public string LastName { get; […]

XMLHttpRequest()JSON抛出网络错误但类似的jQuery .getJSON代码有效

我有一个从外部网站加载的JSON脚本。 在最简单的forms中,代码就像这样(并且正在工作): jQuery.getJSON(“http://adressesok.posten.no/api/v1/postal_codes.json?postal_code=” + document.querySelector(“input”).value + “&callback=?”, function(data){ document.querySelector(“output”).textContent = data.postal_codes[0].city; }); 但是,网站所有者不希望jQuery,如果它.getJSON ,所以我将.getJSON重新编码为request = new XMLHttpRequest(); 模型: request = new XMLHttpRequest(); request.open(“GET”, “http://adressesok.posten.no/api/v1/postal_codes.json?postal_code=” + document.querySelector(“input”).value + “&callback=?”, true); request.onload = function() { var data = JSON.parse(request.responseText); document.querySelector(“output”).textContent = data.postal_codes[0].city; }; request.onerror = function() { /* this gets called every time */ }; 我已多次修改我的代码,一遍又一遍地阅读文档,但.onerror函数是唯一一个始终显示的函数。 这是控制台: […]

Ajax POST到PHP并接收响应,jQuery

所以,我有一个JSON数组,我想POST到一个文件,然后收到一个响应。 但不知何故它似乎没有用,所以我希望你们能帮我一点。 data = JSON.stringify({ “jsonrpc”: “2.0”, “method”: “login”, “id”: 1, “params”: { “params”: { “username”: “1234”, “password”: “4321” } } }); $.ajax({ url:”functions/proxy.php”, type:”POST”, data : data, success: function(data){/* do something*/ }, error: function(data) {/* do something*/)} }); 当我提交表单时, error function运行,我在var_dumping $_POST时得到这个: array(0) { } 奇怪的是,当data看起来像这样: data: “username=1234&password&4321” 我明白了: Array ( [username] => 1291 […]

如何从json获取参数?

完整代码: $.post(‘test.php’, { id: id },function (data) { console.log(data); var Server = data.response.server; var Photo = data.response.photo; console.log(Server); console.log(Photo); }); 在data我得到json: { “server”:9458, “photo”: “[{\”photo\”:\”0d6a293fad:x\”,\”sizes\”: [[\”s\”,\”9458927\”,\”1cb7\”,\”PX_xDNKIyYY\”,75,64], [\”m\”,\”9458927\”,\”1cb8\”,\”GvDZr0Mg5zs\”,130,111], [\”x\”,\”9458927\”,\”1cb9\”,\”sRb1abTcecY\”,420,360], [\”o\”,\”9458927\”,\”1cba\”,\”J0WLr9heJ64\”,130,111], [\”p\”,\”9458927\”,\”1cbb\”,\”yb3kCdI-Mlw\”,200,171], [\”q\”,\”9458927\”,\”1cbc\”,\”XiS0fMy-QqI\”,320,274], [\”r\”,\”9458927\”,\”1cbd\”,\”pU4VFIPRU0k\”,420,360]], \”kid\”:\”7bf1820e725a4a9baea4db56472d76b4\”}]”, “hash”:”f030356e0d096078dfe11b706289b80a” } 我想得到参数server和photo[photo] 为此我使用: var Server = data.server; var Photo = data.photo; console.log(Server); console.log(Photo); 但在concole我得到了undefined 比我使用代码: var Server = data.response.server; var Photo […]

使用jQuery和Yahoo的Geolocation API“无效标签”parsererror

我正在使用jQuery访问Yahoo的Geolocation API。 即使我能够从他们的服务器成功检索数据,我也无法让jQuery成功解析数据。 我已经尝试了$ .ajax()和$ .getJSON,每个都返回相同的失败:parsererror和“invalid label”。 通过我对interwebs的挖掘,我发现“无效标签”很可能是JSON没有被括在括号中的结果,但是在解析之前我无法弄清楚如何将数据包装起来。 我甚至不相信这是问题所在。 这是我的代码: $(document).ready(function() { var url = “http://where.yahooapis.com/geocode?q=39.0334171,-94.8320452&gflags=R&flags=JT&appid=supersecretappid&callback=?”; $.getJSON(url, function() { alert(“success”); }) .error(function(data) { alert(JSON.stringify(data)); }); }); 仅使用$ .ajax的备用版本如下: $.ajax({ url: url, data: {}, dataType: “jsonp”, contentType: “text/plain”, success: function(json) { alert(“success”); }, error: function(x,y,z) { alert(JSON.stringify(x)); } }); 非常感谢提前。

用jquery获取json对象

$.getJSON(“/”, function(data) { var items = []; $.each(data, function(key, val) { items.push(val); }); }); [Authorize] [OutputCache(Duration = 0, VaryByParam = “None”)] public JsonResult myUrl() { var list = _repository.GetAll(); var items = list.Select(c => c.Name).ToList(); return Json(items, JsonRequestBehavior.AllowGet); } 我在服务器端创建一个列表(字符串名称列表)并返回一个JsonResult。 我正在尝试使用jquery在客户端获取列表,以便我可以检查它是否包含特定项目。 上面似乎没有用……有什么建议吗?

.each()方法在IE中不起作用

在成功方法中,我无法循环xml响应。 WebMethod是: Public Shared Function GetTypes(ByVal TypeID As Integer) As String Dim db As New DbManager Dim ds As New DataSet db.AddParameter(“@TypeID”, TypeID) ds = db.ExecuteDataSet(“GetTypes”) ds.Tables(0).TableName = “Types” Dim jsSer As New System.Web.Script.Serialization.JavaScriptSerializer Return jsSer.Serialize(ds.GetXml()) End Function 成功方法是 SuccessMethod: function (response, that) { $(response).find(‘Type’).each(function (index) { alert(“called”); }) }); xml响应是: 12 5 2011-04-24T09:00:00+05:00 Here […]

从getJSON调用的函数中获取返回值

如果$.getJSON()成功获取JSON数据,则调用一个函数,如下所示。 如何捕获返回的值output ? $.getJSON(url, function(data) { // Do stuff with data if succeeds in getting the data return output; } );