【问题标题】:What would be the $.ajax equivalent to this $.getJSON与此 $.getJSON 等效的 $.ajax 是什么
【发布时间】:2014-03-12 21:16:12
【问题描述】:

所以我得到了这个方法:

$.getJSON("http://confidential.com/pcm/datamobile.asmx/ObtenerContactos", {sessionId: 1} , function(data) {
    alert("Success!!! yay");
    peopleList = data;
    jsonIsLoaded();//output your data to console
});

我想把它转换成这种格式的等价物:

$.ajax({
  dataType: "json",
  url: url,
  data: data,
  success: success
});

那会是什么样子?

【问题讨论】:

  • 从文档中不是很清楚吗?我的意思是,您甚至似乎从那里复制了等效的 Ajax。 api.jquery.com/jquery.getjson你到底有什么不明白的?如果您不知道如何阅读:$.getJSON 接受三个参数,名为 urldatasuccess。要获得等效的 $.ajax 调用,请使用显示的模板并将值替换为该参数/参数。
  • 这个问题似乎离题了,因为它已经在文档中得到了回答。

标签: javascript jquery ajax json


【解决方案1】:

官方文档jQuery.getJSON()有明确说明

$.ajax({
  dataType: "json",
  url: "http://confidential.com/pcm/datamobile.asmx/ObtenerContactos",
  data: {sessionId: 1},
  success: function(data) {
        alert("Success!!! yay");
        peopleList = data;
        jsonIsLoaded();//output your data to console
    }
});

【讨论】:

  • 谢谢,比我想象的更直接。
猜你喜欢
  • 1970-01-01
  • 2017-01-27
  • 2023-03-30
  • 2011-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多