我正在使用表单将投注票代码发布到服务器,然后我得到如下内容:
{"tick":[["4032497038600784","0","1.9","516.12","0","19","0","18.01.2014 12:01","0","0","","0"]]...
这是什么语言?如何过滤服务器在 javascript 中返回的内容,并仅向用户显示有关其票证上的匹配项的重要信息?
最佳答案
响应是一个 JSON 字符串。如果您使用的是 jQuery,您可以使用 JSON.parse
或 $.parseJSON
将其解析为 JavaScript 对象。
MDN 上的 JSON.parse:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
编辑:
既然您已经使用了 jQuery,您可以使用 ajax 发布表单并获取响应。以下是获取数据的方法:
$("#gettr").submit(function() {
var url = "path/to/your/phpfile"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
dataType: "json",
data: $("#gettr").serialize(), // serializes the form's elements.
success: function(data) {
// This is where your data wil be avalable. Do something with it here. No need to use JSON.parse as it is already parsed into a JS object.
console.log(data)
}
});
return false; // avoid to execute the actual submit of the form.
});
jQuery.ajax: http://api.jquery.com/jquery.ajax/
关于javascript - 过滤服务器返回的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21217002/