strugglesMen
.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");

分类:

技术点:

相关文章:

  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2021-10-25
猜你喜欢
  • 2021-11-17
  • 2021-10-16
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
  • 2022-12-23
  • 2021-12-16
相关资源
相似解决方案