SharePoint CSOM javascript Get List Fields
var fields;
function GetFieldsForList(ListName)
{
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(ListName);
this.fields = list.get_fields();
ctx.load(fields, 'Include(Title,InternalName)');
ctx.executeQueryAsync(Function.createDelegate(this, this.Success), Function.createDelegate(this, this.Failure));
}
{
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(ListName);
this.fields = list.get_fields();
ctx.load(fields, 'Include(Title,InternalName)');
ctx.executeQueryAsync(Function.createDelegate(this, this.Success), Function.createDelegate(this, this.Failure));
}
function Success()
{
var _fields = '';
var lEnum = fields.getEnumerator();
while(lEnum.moveNext())
{
_fields += lEnum.get_current().get_title() + " - " + lEnum.get_current().get_internalName() + ";";
}
alert(_fields);
}
function Failure(sender, args)
{
alert("Failed" + args.get_message());
}
{
var _fields = '';
var lEnum = fields.getEnumerator();
while(lEnum.moveNext())
{
_fields += lEnum.get_current().get_title() + " - " + lEnum.get_current().get_internalName() + ";";
}
alert(_fields);
}
function Failure(sender, args)
{
alert("Failed" + args.get_message());
}