I have 2 dynamic drop down menus using json . Then thing is with the script I'm using only one will work correctly. I'm not sure where I'm going wrong..

Recommended Answers

how about storing the URL info in an array, then use a loop to iterate through the array members, calling a function (passing the URL param) that executes the ajax process.

Jump to Post

All 3 Replies

Can I only use one? Or can I change one of them some how? As they both do similar things but are calling from a different link..

<script type="text/javascript" language="javascript">
   var url = 'http://www.klcafehelps.com/kl/build.json%3fjsonCallback%3f';
    $(document).ready(function() {
        $.ajax({
            url: url,
            type: 'GET',
            async: false,
            jsonpCallback: 'myCallback',
            contentType: "application/json",
            dataType: "jsonp",
            success: function(jd) {
                $.each(jd, function(i, value) {
                    $('#shop_name').append(
                        $('<option></option>').val(jd[i].value).html(jd[i].desc)) });
            }
        });
    });
</script>
<script type="text/javascript" language="javascript">
   var url = 'http://www.klcafehelps.com/kl/cater.json%3fjsonCallback%3f';
    $(document).ready(function() {
        $.ajax({
            url: url,
            type: 'GET',
            async: false,
            jsonpCallback: 'CaterCallBack',
            contentType: "application/json",
            dataType: "jsonp",
            success: function(jd) {
                $.each(jd, function(i, value) {
                    $('#cater_name').append(
                        $('<option></option>').val(jd[i].value).html(jd[i].desc)) });
            }
        });
    });
</script>

how about storing the URL info in an array, then use a loop to iterate through the array members, calling a function (passing the URL param) that executes the ajax process.

got it thanks

<script type="text/javascript" language="javascript">
   var caternameurl = 'http://www.klcafehelps.com/kl/cater.json%3fjsonCallback%3f';
    $(document).ready(function() {
        $.ajax({
            url: caternameurl,
            type: 'GET',
            async: false,
            jsonpCallback: 'CaterCallBack',
            contentType: "application/json",
            dataType: "jsonp",
            success: function(jd) {
                $.each(jd, function(i, value) {
                    $('#cater_name').append(
                        $('<option></option>').val(jd[i].value).html(jd[i].desc)) });
            }
        });
    });

</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.