1

I am facing an error while working with laravel & Ajax.

Here is my code.

 <button id="openBtn" class="btn blue pull-right"><i class="glyphicon glyphicon-plus"></i> Add Certification</button>

$(".editcertifictns #openBtn").click(function(e){
e.preventDefault();
$.ajax({
  type:'get',
  dataType:'html',
  async:false,
  url:'getcertifications',
  success:function(response){
    $("select[name=certictnsoptn]").html(response);
    $(".modelPophldr,.modelPop").show();
    $("#catagry_name").val("").focus();
    $(".formitmpic").hide();
    $(".modelPop").animate({'margin-top':'25px'});
  },
});

Routes.

 Route::get('getcertifications',['uses'=>'GblgetapiController@getcertifications']);

Controller

public function getcertifications(){
    $arr = DB::table('master_cirtfctnassc')->get();
    $string ="";
    foreach ($arr as $arr) {
        $string .= "<option value='.$arr->cirtfctnassc_name.'>".$arr->cirtfctnassc_name."</option>"
    }
    return $string;
}

Binding area..

  <div class="modelBody">
      <div class="form-group">
        <select class="form-control" name="certictnsoptn">
          <option></option>
        </select>
      </div> 
    </div>

When Clicking on the button, the app will sent an ajax..

I am attaching the screenshot of firebug when ajax perform...

look the URL hovered...:(((((

enter image description here

How can I use the full url in js file without making a issue in migration stage.... Anybody please help me to solve this issue ???? :(:(:(:(:(:(:(

Jishad P
  • 703
  • 2
  • 9
  • 24
  • Do you have a ` – jtheman Sep 17 '15 at 12:45
  • its included a jquery file code dude... – Jishad P Sep 17 '15 at 12:47
  • Well the way you present it above then you have HTML in your js, dude! But for considering the question, why not using a relative URL? Or, use the base URL http://stackoverflow.com/questions/23059918/laravel-get-base-url – jtheman Sep 17 '15 at 12:50
  • i want the full url in js file... not in laravel controller or layout... when i use the url() methord, its getting error :(((( – Jishad P Sep 17 '15 at 12:52
  • Generating HTML code inside controller `getcertifications()` is not cool. – Emeka Mbah Sep 17 '15 at 12:58

1 Answers1

2

To make the Full URL available in all your Javascripts, you could set a global variable somewhere in your page like so (in blade):

<script type="text/javascript">
   var BASEURL = "{!! url('/') !!};";
</script>

So later you can do:

$.ajax({
  type:'get',
  dataType:'html',
  async:false,
  url: BASEURL + 'getcertifications'
});
Emeka Mbah
  • 16,745
  • 10
  • 77
  • 96