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 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持