Laravel filter redirect crashed web page

时间:2015-09-14 16:14:04

标签: php jquery laravel laravel-4 filter

I am using Laravel 4.1 and created a global filter which redirects to a particular page if any of the following value is null.

  • Name
  • email
  • DOB
  • Religion
  • Caste

In the above values Caste is populated dynamically. When the religion value is changed. Everything was working fine With the below code in filter.php:

if (is_null(value->name)) {
    return Redirect::to('confirm');
}   

if (is_null(value->email)) {
    return Redirect::to('confirm');
}   
if (is_null($value->dob) {
    return Redirect::to('confirm');
}

But when I added Religion or caste or both. The jQuery in the page crashes that is the dropdown isn't populating properly and the entire browser hangs.

if (is_null(value->name)) {
        return Redirect::to('confirm');
    }   

    if (is_null(value->email)) {
        return Redirect::to('confirm');
    }   
    if (is_null($value->dob) {
        return Redirect::to('confirm');
    }

    if (is_null($value->religion) {
        return Redirect::to('confirm');
    }

    if (is_null($value->caste) {
        return Redirect::to('confirm');
    }

I don't why it is happening; the first three work completely fine.

jQuery:

var Religion = '#Religion' ;
var Caste = '#Caste' ;


var caste = new Array();
var usr ;
$(function () {
            $.ajaxSetup({
                            async: false
            });

        usr =  getUser();
        if(!$.isEmptyObject(usr))
        {
             var data = getCasteForReligion(usr.religionid) ;
             if (data != null) {
                        // alert(data);
                        caste = new Array();
                        for (var i = 0; i < data.length; i++) {
                            caste.push(data[i]);
                        }
                        loadCastes(caste);
            }
            if(user.casteid != null)
            {
                $(Caste).val(usr.casteid).trigger('list:updated');
            }
        }

        $(Religion).change(function () {
                if ($(Religion).val() != "") {
                    var data = getCasteForReligion($(Religion).val());
                    if (data != null) {
                        // alert(data);
                        caste = new Array();
                        for (var i = 0; i < data.length; i++) {
                            caste.push(data[i]);
                        }
                        loadCastes(caste);
                    }
                }
                else {

                }
        });



});

function getCasteForReligion(religionid) {
    var result;
                $.get('/getCastes',
                        { religionId : religionid },
                    function(data) {
                        result    = data;
                    });
      return result;
}

function getUser() {
    var result;
                $.get( '/User',
                        { },
                    function(data) {
                        result    = data;
                    });
      return result;
}


//Generate Products variant for Indent
function loadCastes(castlst) {
    $(Caste).find('option').remove();
    $(Caste).val('').trigger('list:updated');
    $(Caste).append(new Option("--Select--", "")).trigger('list:updated');
    for (var i = 0; i < castlst.length; i++) {
        $(Caste).append(new Option(castlst[i].name, castlst[i].id)).trigger('list:updated');
    }
}

0 个答案:

没有答案