CodeIgniter Forums
Help me to create choose regional with mysql and ajax - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Help me to create choose regional with mysql and ajax (/showthread.php?tid=75497)



Help me to create choose regional with mysql and ajax - mjamilasfihani - 02-12-2020

I created an api in my localhost, try call it as https://api.example.test/v1/address/id/parameter

the value of parameter is province, district, sub-district and village.

I have created a country list in my ContinueSignUpView that has a id value. And here is my javascript :

Code:
$(document).ready(function(){

    var baseUrl = 'https://api.example.test/v1/address/id/';
    var id      = $(this).val();

    $('#ajax_country').change(function(){
         $.ajax({
             url      : baseUrl + 'province',
             method   : 'POST',
             data     : {id : id},
             async    : true,
             dataType : 'json',
             success  : function(data){
                 var html = '<option hidden="">Province</option>';
                 var i;

                 for(i=0; i<data.length; i++){
                     html += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
                 }
                 $('#ajax_province').html(html);
             }
         });
    });

       /**
        * Another Javascript (parameter)
        *
        */

});

I have checked that request return as 200, but it cant show the province select, Thanks

I also has added in my api .htaccess :

Code:
Header set Access-Control-Allow-Origin "*"



RE: Help me to create choose regional with mysql and ajax - jreklund - 02-13-2020

Hi, make a console.log(data) after the success. And see in your console that you are returning anything.


RE: Help me to create choose regional with mysql and ajax - mjamilasfihani - 02-13-2020

(02-13-2020, 10:54 AM)jreklund Wrote: Hi, make a console.log(data) after the success. And see in your console that you are returning anything.

Okay, thanks I'll try it


RE: Help me to create choose regional with mysql and ajax - mjamilasfihani - 02-13-2020

Well its done Smile thanks for your help. The problem is, the environment should be set as production, because the CI debug annoyed the jquery return

(02-13-2020, 10:54 AM)jreklund Wrote: Hi, make a console.log(data) after the success. And see in your console that you are returning anything.

I want ask something, this is bug or from CI 4 ignore all jquery return when I set environment as development?


RE: Help me to create choose regional with mysql and ajax - jreklund - 02-14-2020

Hi, I haven't used CI4 yet in any big capacity. So I can neither confirm or deny that. :-)

What type of error did you get in return from CI in development/debug mode? That broke jQuery?


RE: Help me to create choose regional with mysql and ajax - mjamilasfihani - 03-19-2020

(02-14-2020, 12:19 PM)jreklund Wrote: Hi, I haven't used CI4 yet in any big capacity. So I can neither confirm or deny that. :-)

What type of error did you get in return from CI in development/debug mode? That broke jQuery?

The debug tools was read while it returned, so it broke the jquery. I think it's not a bug.

I saw it in firefox console