php - Jquery Form Output -
i have function sends specified form data php processing page.
function get(){ $.post('data.php',{"name":$('#fname').val(),"age":$('#age').val()}, function(output){ $('#rage').hide().html(output).fadein(1000); }); }
after posting script takes outputs php page (ie: echo's) , puts them in #rage div. $('#rage').hide().html(output).fadein(1000);
i wondering possible have 2 different outputs each of inputs.
by mean echo response "name":$('#fname').val()
goes #rname , echo response "age":$('#age').val() goes #rage.
i hope have explained myself enough.
cheers guys.
you have php script return json keys, , in callback function, assign values respective elements.
say had php script return this:
header('content-type: application/json'); $return_obj = array('age' => 'someage', 'name' => 'somename', 'success' => true); echo json_encode($return_obj); //{"age": "someage", "name": "somename", "success":true}
you on client side:
$.ajax({ url:'data.php', type:'post', data: {"name":$('#fname').val(),"age":$('#age').val()}, datatype: 'json', success:function(json) { if(json.success) { $('#age').val(json.age || ''); $('#fname').val(json.name || ''); } } });
Comments
Post a Comment