Ajax post request(SOLVED BY Willvin) September 20, 2019, 11:56:07 AM Good afternoon PHPRADERS, i am having issues with ajax post request. How do i send data to the specified URL. It doesn't seem to work after updating to this latest release. HELP!!!Secondly, i cant seem to create custom functions in the sharedcontroller. How do i accomplish this in PhPraD. Thanks for the assistance. Quote Selected Last Edit: January 11, 2020, 08:59:43 PM by ubbxst
Re: Ajax post request Reply #1 – September 21, 2019, 02:55:31 PM @ubbxst create a sample project or explain in detail how and where you are making an ajax post request to.Thanks. Quote Selected
Re: Ajax post request Reply #2 – September 24, 2019, 03:57:53 PM Thanks @willvin for the response and interest. i want values from list-box 1 and list-box 2 to determine the value list-box3 should contain. I did this:$('#ctrl-section').on('change', function(){ var cname= $('#ctrl-class').val(); var sname =$('#ctrl-section').val(); $.ajax({ url:'score/getnames.php', type:'post', data:{cname:cname,sname:sname}, dataType:'json', success:function(response){ //$('#ctrl-student_name').empty(); $('#ctrl-student_name').html(response); } }); });=============================================//getnames.php file$lookup_class=$_POST['cname'];$lookup_section=$_POST[sname];$db = $this->GetModel(); $sqltext = "SELECT CONCAT(first_name,' ',middle_name,' ',surname) AS fullname FROM student WHERE class= ? AND section= ?"; $queryparams = array($lookup_class,$lookup_section); $arr = $db->rawQuery($sqltext,$queryparams);$flnames= array(); foreach($arr as $fullnames){ $studname= $fullnames['fullname']; $flnames[] = array("names"=> $studname); } echo json_encode($flnames);view the image attached.the output gives empty options.Thanks once agian. Quote Selected
Re: Ajax post request Reply #3 – September 25, 2019, 08:56:49 AM @ubbxst this should populate that field for you, assuming your PHP code returns a JSON data and your ajax post request gets the data from it. Add this 👇 into your success function.Code: [Select]var $stdname= $("#ctrl-student_name");$.each(JSON.parse(response), function() { $stdname.append($("<option />").val(this.flnames).text(this.flnames));});flnames should be each variable that holds the name in the JSON data. Quote Selected
Re: Ajax post request Reply #4 – September 26, 2019, 03:00:32 PM Thanks @wilvin for your response but its not working. i tried another approach of sending the data through controller(score/getnames/cname/sname), but still not working. it cant retrieve data from the student table to populate the list.Note: the controller is ScoreController(getnames is a method in here). the View is score/add.php(this is where the ajax request is written). Quote Selected
Re: Ajax post request Reply #5 – October 30, 2019, 06:55:40 PM This will help other user that have the same problem with ajax.I know the root cause why it not working in newer version phprad.Because of when we call ajax url,it not go to root path.As in ubbxst code isCode: [Select]url:'score/getnames.php',score folder is next from root path.If this ajax is use in url = {root_path}/customer/add,Ajax not go to right url.It will call to{root_path}/customer/add/score/getnames.php. (the correct url is {root_path}/score/getnames.php)So,to fix it.Your url must add ../ in your code. Code: [Select]url:'../score/getnames.php',Ajax will go to correct url and working again. Quote Selected 1 Likes
Re: Ajax post request Reply #6 – November 07, 2019, 09:40:24 AM Good morning @tin and thanks for your aid. I'll try that out now. Quote Selected
Re: Ajax post request Reply #7 – November 29, 2019, 11:59:55 AM Good afternoon @tin that did not work as well. Quote Selected
Re: Ajax post request Reply #8 – December 16, 2019, 08:32:33 AM Quote from: ubbxst – November 29, 2019, 11:59:55 AMGood afternoon @tin that did not work as well.@ubbxst Please paste your code.It work for me. Quote Selected