javascript - How to get json data coming from ajax and show it prefilled in input box -
following code ii have used response in json
. when add alert alert(response.subject);
returns "undefined"
html:
<input type="text" id="subject" value='subject'>
javascript:
$.ajax({ url: "/ebays/prefilledcontentajax", type: "post", cache: false, async: true, data: { type: $("#type").val(), }, success: function (response) { console.log(response); // show json response returns. want show in input box prefilled data response return } });
please me out.
you can use val
set value in textbox
$('#subject').val(response[0].subject);
also, might want change ajax
call:
$.ajax({ url: "/ebays/prefilledcontentajax", type: "post", cache: false, async: true, data: { type: $("#type").val(), }, datatype: "json", // ^^^^^^^^^^^^^ success: function (response) { // response json $('#subject').val(response[0].subject); } });
val
set value of each element in set of matched elements.
http://api.jquery.com/val/#val2
ajax
perform asynchronous http (ajax) request.
Comments
Post a Comment