Puneet Arora
asked on
Dropdown Not Populating From Ajax Post Call due to java script conflict
Dear ,
Drop Down Not Populating From Ajax Post Call due to java script conflict , But , if some dummy
option of Select control is filed {A,B,C } , on selection it shows data from ajax call .Kindly check the
images attached and the code embedded also .
3.png
Drop Down Not Populating From Ajax Post Call due to java script conflict , But , if some dummy
option of Select control is filed {A,B,C } , on selection it shows data from ajax call .Kindly check the
images attached and the code embedded also .
(function($){
/* Complete jquery code must be wrapped under this function
It is a good practice to include this complete code in a sepearte js file and include it after all other referred files in the document
(I included this myjs.js just before </html>, or we can in the footer of file.... Programmers tend to to this for lesser conflict )
If you are creating another seperate file better to use a another symbol in place of $ for this function
*/
$(document).ready(function(e) {
//Best practice is to add this document.ready function only once in the file.
// get your ajax values before initializing the selectbox plugin
var fk_i_id = 0;
if(fk_i_id === 0)
{
$.ajax({
type:'post',
url:'../api1.php?getlist=categorya',
datatype: 'json',
data: {id:fk_i_id},
success: function(data){
var opts = JSON.parse(data);
$('#s2').empty();
$.each(opts, function(i, d) {
$('#s2').append('<option value="' + d.pk_i_id + '">' + d.s_name + '</option> ').html();
});
}
});
}
// Inititalize first selectbox
$("#s22").dropdownchecklist( {
forceMultiple: true,
onComplete: function(selector) {
var values = "";
for( i=0; i < selector.options.length; i++ ) {
if (selector.options[i].selected && (selector.options[i].value != "")) {
if ( values != "" ) values += ";";
values += selector.options[i].value;
}
}
alert( values );
},
onItemClick: function(checkbox, selector){
var justChecked = checkbox.prop("checked");
var checkCount = (justChecked) ? 1 : -1;
for( i = 0; i < selector.options.length; i++ ){
if ( selector.options[i].selected ) checkCount += 1;
}
if ( checkCount > 3 ) {
alert( "Limit is 3" );
throw "too many";
}
}
});
// Inititalize second selectbox
$("#s2").dropdownchecklist( {icon: {}, width: 750 } );
[embed=file 933796]
});
})(jQuery);
// This (jQuery) callback is essential for making $ function work properly
2.png3.png
ASKER
Data is coming 1000% , if you need screen shot I can send it
Yes kindly print it.
ASKER
Dear Ahmed Merghani
[{"FilterNameID":"4","Filt erName":"P ostet By","FilterValue":"Authori sed Dealership","CategoryAID": "12","Cate goryBID":" 18"},{"Fil terNameID" :"4","Filt erName":"P ostet By","FilterValue":"Used Car Dealers","CategoryAID":"12 ","Categor yBID":"18" },{"Filter NameID":"4 ","FilterN ame":"Post et By","FilterValue":"Owner", "CategoryA ID":"12"," CategoryBI D":"18"},{ "FilterNam eID":"5"," FilterName ":"Fuel Type","FilterValue":"Petro l","Catego ryAID":"12 ","Categor yBID":"18" },{"Filter NameID":"5 ","FilterN ame":"Fuel Type","FilterValue":"Disea l","Catego ryAID":"12 ","Categor yBID":"18" },{"Filter NameID":"5 ","FilterN ame":"Fuel Type","FilterValue":"CNG", "CategoryA ID":"12"," CategoryBI D":"18"},{ "FilterNam eID":"5"," FilterName ":"Fuel Type","FilterValue":"LPG", "CategoryA ID":"12"," CategoryBI D":"18"}]
[{"FilterNameID":"4","Filt
ASKER
I was trying with this json data populate dropbox having check boxes based on <script type="text/javascript" src="dist/js/bootstrap-mul tiselect.j s"></scrip t> library .
[{"FilterValue":"Petrol"}, {"FilterVa lue":"Dise al"},{"Fil terValue": "CNG"},{"F ilterValue ":"LPG"}]
The data is coming as above from ajax call , but is not rendered in dropdown , I don't why , please help
in this case , I m using bootstrap-multiselect.js.
[{"FilterValue":"Petrol"},
The data is coming as above from ajax call , but is not rendered in dropdown , I don't why , please help
in this case , I m using bootstrap-multiselect.js.
function callC(FilterName) {
$.ajax({
type: "POST",
url: "./api1.php?getlist=filtervals&id="+FilterName,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result) {
//var myHtml = '<p>' +FilterName+'<p> </br>'; //loop var categories = [];
var myHtml = '';
for (var i = 0; i < result.length; i++) {
var item = result[i].FilterValue ;
var myHtml = '<option value="' + item + '">' + item+ '</option>';
//myHtml += "<li>" +item + "</li>";
}
alert(myHtml);
$("#p10").append(myHtml);
}
});
}
<select id="p10" multiple="multiple" name = "p10">
</select>
Where do you call function "callC(FilterName)" ??
ASKER
I call this function in document ready function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks , the main reason was javascript conflict , I was able to solve it earlier , any way thanks for the
support !
support !
Open in new window