[英]Ajax Call not returning Partial View
我正在进行AJAX
调用,然后从Controller返回PartialView
以将其填充到div
。
以下是我的代码:-
var file = document.getElementById("file").files[0];
jq.ajax({
type: "POST",
url: '/Main/getData',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
jq('#partialPlaceHolder').html(response);
},
error: function (error) {
alert("Some Error Occured");
}
});
[HttpPost]
public ActionResult getData(FormCollection form)
{
......
return PartialView("_pageMain", retMod);
}
当我在Controller中调试代码时,直到最后都没有错误,但是AJAX仍然会alert("Some Error Occured")
。
未在div中填充PartialView。 如何解决呢?
您正在将返回数据类型设置为json
dataType: 'json'
尝试将其更改为
dataType: 'html'
看到这里http://api.jquery.com/jquery.ajax/
dataType (默认值:Intelligent Guess(xml,json,脚本或html))类型:String期望从服务器返回的数据类型。
为什么不使用.load()
JQuery .load() ?
描述:从服务器加载数据并将返回的HTML放入匹配的元素。
很简单:
$('#partialPlaceHolder').load("@Url.Action('getData')", { form: formData })
.load()
第三个参数是回调函数,因此可以.load()
使用。
顺便说一句:我没有在您的代码中找到使用变量file
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.