this is not asp.net mvc, this is asp.net webforms
I am trying to send object literal like this
templateProperties = {}
and my ajax call like this
$.ajax({
beforeSend:updateTemplateProperties,
type: "POST",
url: templatePropertiesUpdateUrl,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({ "templateProperties": templateProperties }),
}).done(function (data) {
log(data.d);
});
I am calling function before sending:
updateTemplateProperties = function () {
templateProperties.NameFont = "qwq";
templateProperties.NameBold = true;
templateProperties.NameItalic = false;
templateProperties.NameFontColor = "#FFF";
templateProperties.NamePositionX = 52;
templateProperties.NamePositionY = 896;
templateProperties.NameSize = 23;
templateProperties.DateFont = "ssda";
templateProperties.DateBold = false;
templateProperties.DateItalic = true;
templateProperties.DateFontColor = "#EEE";
templateProperties.DatePositionX = 47;
templateProperties.DatePositionY = 236;
templateProperties.DateSize = 12;
}
adn My webmethod is like that
[WebMethod]
public static string UpdateTemplateProperties(TemplateProperties templateProperties)
{
var serializer = new JavaScriptSerializer();
return serializer.Serialize(templateProperties);
}
and this is my TemplateProperties class
[Serializable]
public class TemplateProperties
{
public string NameFont { get; set; }
public string NameBold { get; set; }
public string NameItalic { get; set; }
public string NameFontColor { get; set; }
public string NamePositionX { get; set; }
public string NamePositionY { get; set; }
public string NameSize { get; set; }
public string DateFont { get; set; }
public string DateBold { get; set; }
public string DateItalic { get; set; }
public string DateFontColor { get; set; }
public string DatePositionX { get; set; }
public string DatePositionY { get; set; }
public string DateSize { get; set; }
}
when checking templateProperties I found the entire object properties equal to null
{"NameFont":null,"NameBold":null,"NameItalic":null,"NameFontColor":null,"NamePositionX":null,"NamePositionY":null,"NameSize":null,"DateFont":null,"DateBold":null,"DateItalic":null,"DateFontColor":null,"DatePositionX":null,"DatePositionY":null,"DateSize":null}
I am not getting any error from this call, and I have tried everything I know but it is not working normally I pass the parameters individually to the webmethod one by one but this time they are too much to do so , So I want to send the whole object as one entity
由于某种原因,调用了beforeSend
回调函数updateTemplateProperties
,但是在发送数据之前未正确初始化templateProperties
,我只是在开始ajax调用之前调用了updateTemplateProperties
函数,它现在可以正常工作,但是我真的不知道为什么会这样不能这样工作
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.