如何使用 YAHOO connect 和 json 向控制器发送数据
我无法使用 YAHOO 连接库将数据发送到 MVC 控制器。
参数查询和过滤器均为NULL。问题出在哪里?
// --- JavaScript --- //
var callbacks = {
// Successful XHR response handler
success: function (o) {
var messages = [];
// Use the JSON Utility to parse the data returned from the server
try {
messages = YAHOO.lang.JSON.parse(o.responseText);
}
catch (x) {
alert("JSON Parse failed!");
return;
}
handleSearchResult(messages, query, filter);
},
argument: { query: "flowers", filter: "home" }
};
// Make the call to the server for JSON data
YAHOO.util.Connect.asyncRequest("GET", "Search/GetTopics", callbacks);
// --- C# --- //
//Controller
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetTopics(string query, string filter)
{
// query and filter are NULL <- problem here //
// ...do my stuff... //
return Json(Search(query, filter), JsonRequestBehavior.AllowGet);
}
谢谢你! :)
I can not send data to MVC controller using YAHOO connect library.
Parameters query and filter are NULL. Where is the problem?
// --- JavaScript --- //
var callbacks = {
// Successful XHR response handler
success: function (o) {
var messages = [];
// Use the JSON Utility to parse the data returned from the server
try {
messages = YAHOO.lang.JSON.parse(o.responseText);
}
catch (x) {
alert("JSON Parse failed!");
return;
}
handleSearchResult(messages, query, filter);
},
argument: { query: "flowers", filter: "home" }
};
// Make the call to the server for JSON data
YAHOO.util.Connect.asyncRequest("GET", "Search/GetTopics", callbacks);
// --- C# --- //
//Controller
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetTopics(string query, string filter)
{
// query and filter are NULL <- problem here //
// ...do my stuff... //
return Json(Search(query, filter), JsonRequestBehavior.AllowGet);
}
Thank you! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须有可能发送参数:
使用 GET 动词:在这种情况下,您需要在查询字符串中传递参数:
使用 POST 动词:在这种情况下,您可以使用 postData 参数
在第一种情况下,实际上建议使用 Url 助手来生成地址,以确保值正确进行 url 编码:
第二种情况也是如此。确保正确编码值。
You have to possibilities to send parameters:
Use GET verb: In this case you need to pass the parameters in the querystring:
Use POST verb: In this case you could use the postData parameter
In the first case it is actually recommended to use Url helpers to generate the address to make sure values are properly url encoded:
The same is true for the second case. Make sure to properly encode values.