Senin, 21 Desember 2020

ajax fill from json

 contoh 1


	function loadbrg(id,vnd){
		document.forms['fmedit'].querySelectorAll('input[name^="a"]').forEach(function(el){el.value='';});
		$("#modaledit").modal();
		//if(id==0)document.forms['fmtarget'].querySelectorAll('input[name^="a"]').forEach(function(el){el.value=el.name;});
		if(id==0)return;
		var oTXT=document.forms['fmedit'].querySelectorAll('input[name^="a"]');
		$.post("?act=loadbrg&id="+id+"&vnd="+vnd).done(function(response){
			console.log(response);
			$.each(oTXT, function( key, value ) {
				var otxt=value.name.replace('a[','').replace(']','');
				value.value=response[otxt];
				//console.log(key+"="+value.value+"->"+otxt);
			});
		});
	}


contoh 2


	var fmtarget=document.forms['fmpopup'];
	fmtarget.querySelectorAll('input').forEach(function(el){el.value='';});
	$.post("?act=loadlembar",{idobj:idobj}).done(function(response){
		console.log(response);
		$.each(response, function( key, value ) {
			try {
				fmtarget["a["+key+"]"].value=value;
			}
			catch(err) {console.log("a["+key+"]"+err.message);}
		});
	});

Foto Propades