i want receive data using ajax. when use code, result prints [object htmlinputelement]. can change object string?
here's code in jsp use ajax.
$('select#product').change(function() { var param = "code=" + $('#product').val(); $.ajax({ url : 'add_products/add_products.jsp', contenttype : "application/x-www-form-urlencoded; charset=utf-8", data : param, type : 'post', datatype : 'text', success : function(data, textstatus, jqxhr){ $('#color').val(color); $('#price').val(price); } }); }); ... <td> <input type="text" id="color" class="form-control" name="color" /> </td> <td> <input type="text" id="price" class="form-control" name="price" value="0" /> </td> and add_products.jsp receive upper jsp.
product_code = request.getparameter("code"); try { query = "select * new_product product_code='"+product_code+"'"; rs = stmt.executequery(query); while (rs.next()) { size = rs.getstring("sizes"); color = rs.getstring("color"); price = rs.getstring("price_cny"); out.println(color); out.println(price); } } catch (sqlexception e) { out.println(e); } { } thanks.
change server code this...
product_code = request.getparameter("code"); try { query = "select * new_product product_code='"+product_code+"'"; rs = stmt.executequery(query); while (rs.next()) { size = rs.getstring("sizes"); color = rs.getstring("color"); price = rs.getstring("price_cny"); out.println(color+"_"+price); //concatenate 2 values } } catch (sqlexception e) { out.println(e); } { } and client code this...
$('select#product').change(function() { var param = "code=" + $('#product').val(); $.ajax({ url : 'add_products/add_products.jsp', contenttype : "application/x-www-form-urlencoded; charset=utf-8", data : param, type : 'post', datatype : 'text', success : function(data, textstatus, jqxhr){ var values = data.split("_"); //get 2 values seperated $('#color').val(values[0]); $('#price').val(values[1]); } }); });
Comments
Post a Comment