[英]What is a JSON Data Source?
I am working on a C# console application using the Nancy Framework and the Spark view engine, and I am trying to replicate something from another project. 我正在使用Nancy Framework和Spark视图引擎在C#控制台应用程序上工作,并且正在尝试从另一个项目中复制某些内容。 However, I am very inexperienced with both Javascript and JSON.
但是,我对Javascript和JSON都缺乏经验。 To call a chat function in my C# code from my HTML, right now I simply use something like the following...
要从我的HTML中用C#代码调用聊天功能,现在,我只需要使用以下内容即可...
HTML: HTML:
http://localhost:1234/sendchat?message="this is a test message"
C# Code: C#代码:
Get["/sendchat"] = x =>
{
string message = Request.Query.message;
string message2 = message.Replace("\"", "");
Console.WriteLine(message2);
return View["console.spark"];
};
The problem is that this causes the page to reload. 问题在于这会导致页面重新加载。 In the project I am looking at for reference, they use Javascript/JSON to call the same type of function without doing a page reload.
在我正在寻找参考的项目中,它们使用Javascript / JSON来调用相同类型的函数,而无需重新加载页面。 I understand all of it except for the JSON line as I don't understand what the DataSource is...
我了解所有内容,但JSON行除外,因为我不了解数据源是什么...
$(document).ready(function () {
$("#typechat").keypress(function (event) {
if (event.keyCode == '13') {
event.preventDefault();
message = escape($("#typechat").attr('value'));
$.getJSON(dataSource + "?req=sendchat&message=" + message);
$("#typechat").attr('value', "");
}
});
});
dataSource
is just an http domain like http://yourserver.com/possibly/with/a/path
. dataSource
只是一个http域,例如http://yourserver.com/possibly/with/a/path
。 It'll be a string defined somewhere in the code. 这将是代码中定义的字符串。
JSON resources are fetched just like regular HTML pages, with a normal GET request over HTTP. JSON资源的获取与常规HTML页面一样,通过HTTP进行常规的GET请求。 The only difference is the content is JSON not HTML.
唯一的区别是内容是JSON而不是HTML。 Try this in your browser for example to see the JSON returned by the SO api:
在浏览器中尝试此操作,例如查看SO api返回的JSON:
http://api.stackoverflow.com/1.1/users/183579 http://api.stackoverflow.com/1.1/users/183579
(If you don't have a browser plugin to format/highlight JSON nicely it might just look like a long messy string) (如果您没有用于很好地格式化/突出显示JSON的浏览器插件,则可能看起来像一个长而乱的字符串)
Data source is propobly some web page 数据源大概是某个网页
dataSource = "http://somepage.com/someaction";
wich renders response as json text, response is grabbed and then parsed to javascript object wich将响应呈现为json文本,获取响应,然后解析为javascript对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.