duannian4784 2015-09-17 12:42
浏览 43
已采纳

Laravel Jquery Ajax 404错误和迁移URL问题

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 ???? :(:(:(:(:(:(:(

  • 写回答

1条回答 默认 最新

  • douniani679741 2015-09-17 12:56
    关注

    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'
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作