0
只是想知道,我怎樣才能綁定一個圖像(流)通過ajax調用中的操作方法返回的圖像元素使用jQuery。使用jquery渲染圖像(流對象)
的JavaScript:
$(document).ready($(function() {
$(':input').change(function() {
// object
var Person = {
Name: 'Scott',
Address: 'Redmond'
};
// Function for invoking the action method and binding the stream back
ShowImage(Person);
});
}));
function ShowImage(Person) {
$.ajax({
url: '/Person/GetPersonImage',
type: "Post",
data: JSON.stringify(Person),
datatype: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
// idImgPerson is the id of the image tag
$('#idImgPerson')
.attr("src", data);
},
error: function() {
alert('Error');
}
});
操作方法:
public FileContentResult GetPersonImage(Person person)
{
// Get the image
byte[] myByte = SomeCompnent.GetPersonImage(person);
return File(myByte, "image/png");
}
問題:
行動方法返回流,但沒有得到呈現在這一頁。 我在這裏錯過了一些東西...
感謝您關注它。
您正在使用'datatype:「json」'。根據指定您希望服務器返回的數據類型的API文檔。嘗試刪除它。 – 2011-05-17 16:03:49