Can't display ajax call return
Hey guys, first time posting here and I'm rather new to web programming. This is a pretty mundane question ( I've tried many other place but no one seems to want to help / direct me in the right direction). Here's the thing I have an ajax call that is sent to a controller file ( I'm using Yii MVC) and I've tried a million thing but nothing is returning
Ajax call:
- $('#validate').on('click',function(){
- var data = []; // data container
- // collect all the checked checkboxes and their associated attributes
- $("table#subsection_table input[type='checkbox']:checked").each(function(){
- data.push({
- section : $(this).data('sectionid'),
- subsection : $(this).val(),
- year : $(this).data('year')
- })
- });
- // JSON it so that it can be passed via Ajax call to a php page
- var data = JSON.stringify(data);
- $.ajax({
- url : "<?php echo Yii::app()->createAbsoluteUrl("scheduler/ScheduleValidation"); ?>",
- type: "POST",
- data : "myData=" + data,
- success : function(data)
- {
- $("#ajax-results").html(data);
- $("#ajax-results").dialog({ width: 500, height: 500})
- },
- error: function()
- {
- alert("there was an error")
- }
- })
- console.log(JSON.stringify(data));
- $('#dialog').html(data).dialog({ width: 500, height: 500});
});
Here's my call from the controller. Now, for you that knows Yii you can use renderPartial function to generate a new HTML page. However, I just want to append to my original file... So ( this is from someone who's used it before) I've been told to echo "valid" or "invalid" and then deal with it in the JQuery part. Though, even that isn't working.
Here's the back end function
- public function actionScheduleValidation()
- {
- $post_data = $_POST['myData'];
- $decodedData = json_decode($post_data, true);
- //$course = [[[]]];
- $course=[];
- $counter = 0;
- //Save the years associated to sections chosen
- /**** SQL call --> works fine ****////
- Here, if a certain array isn't empty you go through every array
- [....]
- }
- if($courseYear4Winter != null) {
- $winterErr = verification($courseYear4Winter);
- $errorArr[$counter2] = $winterErr;
- }
- if(errArr != null){
- echo "invalid";
- }
- else
- echo "valid"; }
However, I can't get my view file to display anything whatsoever. I can't use append(), or html() or anything. It just won't show. Any idea on how I can fix this?