有人能告诉我两个JSON解析器之间有什么区别吗?
https://github.com/douglascrockford/JSON-js/blob/master/json.js
https://github.com/douglascrockford/JSON-js/blob/master/json2.js
我有一个2007-04-13的JSON文件(它有方法,如parseJSON).我没有在任何新版本中看到这些方法.
请帮忙.在我的ajax调用中获取错误无效的JSON原语,在ajax调用之后这是错误的
$.ajax({
url: "/Precedent/ShowPartyContents", type: "POST",
contentType: 'application/json; charset=utf-8',
dataType: 'html',
data:{'partyId':party,'PartySelCombo':valueFrom,'DocumentId':DocId},
sucess:function(result){
alert("String"+ result);
//jq("#PartyTagContentArea-"+ pass cheyyenda id).html(data).fadeIn();
},
error : function( ts ){
alert("error :(" + ts.responseText);
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢
我刚刚花了六个小时试图把这个直接放在我脑海里,但我还没有成功.
我的本地机器上有一个HelloWorld .NET 3.5 Web服务.根据需要进行设置.
该服务返回一个List自定义结构.
我正在尝试使用jQuery 1.4.4来使用它.
当我尝试执行文档所说的内容时,我总是从服务中获取XML响应,该响应要么导致parseerrorjQuery ,要么作为哑字符串传递给success函数.也就是说,然而我结合dataType和accepts(其中,根据该文件,控制如何接收数据的处理),我得到一个XML回来.
但是,当我从文档中做一些逻辑上没有的事情时,我成功地获取了我的对象数组.也就是说,当我忽略dataType和accepts,并设置contentType: "application/json; charset=utf-8"相反,它工作正常.但是contentType,根据文档,控制发送到服务器的数据,而不是接收.
$.ajax(
{
type: "GET",
url: "http://localhost:52624/Service1.asmx/HelloWorld",
dataType: "json",
//accepts can be anything, or it can be missing, doesn't matter, only depends on dataType
success: function(data, textStatus, jqXHR) {...},
error: function(jqXHR, textStatus, errorThrown) {...}
}
)
Run Code Online (Sandbox Code Playgroud)
结果:错误处理程序调用,textStatus = …
我试图建立对asp.net mvc控制器的ajax请求,但它给我内部服务器错误
// My Products Controller
[HttpPost]
public ActionResult FilterCategeory(int prodID)
{
var categs = new Categ() {PROD_ID=prodID }.Search();
return Json(categs);
}
//My ajax request
$("#categs").empty();
var prm = $("#prods").val();
$.ajax({
type: "POST",
url: '@Url.Action("FilterCategeory", "Products")',
contentType: "application/json; charset=utf-8",
data: {prodID: prm },
dataType: "json",
success: function (data)
{
alert('Success');
},
error: function () { alert('error');}
});
Run Code Online (Sandbox Code Playgroud) 真痛苦!我正在尝试从JavaScript调用Web服务,但似乎无法找到使其正常工作所需的魔力。
我的代码如下所示:
JavaScript:
$.ajax({
url: "/Services/CompanyContactServices.asmx/AddContact",
type: 'POST',
contentType: "application/json",
dataType: "json",
data: {
companyId: 3725, firstName: firstName, lastName: lastName, email: email
},
success: function (data) {
alert('Success!');
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
Run Code Online (Sandbox Code Playgroud)
Web服务(asmx.cs):
[WebService(Namespace = CompanyListServices.XmlnsNamespace)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class CompanyContactServices : System.Web.Services.WebService
{
public const string XmlnsNamespace = "mynamespace";
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string AddContact(int companyId, string firstName, string lastName, string email)
{
return new JavaScriptSerializer().Serialize(0);
}
} …Run Code Online (Sandbox Code Playgroud) jquery ×4
ajax ×2
web-services ×2
.net-3.5 ×1
asmx ×1
asp.net-ajax ×1
asp.net-mvc ×1
c# ×1
json ×1