here i have created function for calling json but its not working......how to call it?
function get_company_expenses_type(element_id){ $.ajax({
url: "../../modal/get_companyexpenses_type.php",
dataType: "html",
type: 'POST',
success: function(json){
var result = jQuery.parseJSON(json);
length=result.length;
for(k=1;k<=length;k++) {
$('#'+element_id+' option').last().after('<option value="result.'+row1.company_expenses_type_id+'">'+result.row1.company_expenses_type+'</option>');
}
} });
} $(document).ready(function(){
var cnt = 1; $("#anc_add").click(function(){
cnt++;
$("input[id=rows]").val(cnt);
$('#tbl1 tr').last().after('<tr><td><select name="'+cnt+'1"><option value="0">Select Expenses Type</option>X</select></td><td><textarea name="'+cnt+'2"></textarea></td><td><input type="text" name="'+cnt+'3"></td></tr>'); });
get_company_expenses_type('11');
Change the dataType: "html"
to dataType: "json"
, if you are expecting a JSON response application/json
from server.
From jQuery Documentation
dataType: The type of data that you're expecting back from the server
Also no need of using var result = jQuery.parseJSON(json);
. This can be used when you return a json formatted string text/plain
response from server.
You have to do two things in your code:
change
dataType:"html"
to
dataType:"json"
because the request returns json
as this seems to be in your post.
In your code i just saw you are targeting the id which is not there:
$('#'+element_id+' option')
so this has to be:
$('[name*="'+element_id+'"] option')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.