您的位置:首页 > Web前端 > JQuery

关于jquery中ajax数据返回类型问题

2011-04-26 16:06 676 查看
.net方法
namespace Controllers{public class DocumentController{
  
public ActionResult Index(){return View();}
public string GetDocumentUrl(){return Comment.documentUrl;}}}
这中方式取不到值,原来我使用dataType:'json' 而。net中的方法返回值是string类型的。改成dataType: 'Text'就好了,或者直接去掉dataType:'json' 它会自动匹配数据类型的。dataType的解释:dataType (String) : (默认值:智能判断xml或者html)预期服务器返回的数据类型。如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息返回 responseXML 或 responseText,并作为回调函数参数传递,可用值:"text": 返回纯文本字符串
documentUrl = function () {var url = "0";$.ajax({type: 'post',url: '/Document/GetDocumentUrl',dataType: 'json',success: function (data) {url = data;}});return url;}
或者使用这种方法
$.post("/Document/GetDocumentUrl", function (data) { alert(data); });
或者加上数据类型"Text",使用"json"同样是不行的:
$.post("/Document/GetDocumentUrl", function (data) { alert(data); }, "Text");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: