ajax调用适用于chrome和IE,但不适用于firefox

时间:2016-07-22 11:24:48

标签: javascript php jquery ajax

我有这个简单的表单以及对.php文件的关联ajax调用。

使用IE或Chrome时,通话工作正常(即我得到了我想要的结果),但不适用于Firefox。

从我在Firefox调试中看到的是,对search.php的调用未正确执行(即标记为红色)。

有人可以帮助我吗?

以下是表格:

<form id="form_search" accept-charset="UTF-8" enctype="multipart/form-data">
    <div class="radio"><label><input type="radio" name="timeRange" value="24h">Last 24 hours</label></div>
    <div class="radio"><label><input type="radio" name="timeRange" value="week">Last 7 days</label></div>
    <div class="radio"><label><input type="radio" name="timeRange" value="month" checked="checked">Last 30 days</label></div>
    <div class="radio"><label><input type="radio" name="timeRange" value="quarter">Last 3 months</label></div>
    <div class="radio"><label><input type="radio" name="timeRange" value="semi">Last 6 months</label></div>
    <div class="radio"><label><input type="radio" name="lang" value="english" checked="checked">English</label></div>
    <div class="radio"><label><input type="radio" name="lang" value="french">French</label></div>
    <div class="radio disabled"><label><input type="radio" name="lang" value="norwegian" disabled>Norwegian</label></div>
    <div class="radio disabled"><label><input type="radio" name="lang" value="german" disabled>German</label></div>
    <button class="btn btn-primary" type="submit" id="btnSearch">Search</button>

和javascript:

$("#form_search").submit(function(){    

  $('#btnSearch').hide();

  var keyword = $('#keyword').val(); keyword = $.trim(keyword);
  //console.log("keyword: "+keyword);

  var timeRange = $("input[type='radio'][name='timeRange']:checked").val();  
  // transform timeRange to unixtime
  var currentTimeStamp = Math.floor(Date.now()/1000); // current browser unix timestamp in seconds  
  if (timeRange == '24h') {timeRangeUnix = currentTimeStamp - 24*3600} // 1 hour = 3600 seconds 
  if (timeRange == 'week') {timeRangeUnix = currentTimeStamp - 7*24*3600} // 1 hour = 3600 seconds
  if (timeRange == 'month') {timeRangeUnix = currentTimeStamp - 30*24*3600} // 1 hour = 3600 seconds
  if (timeRange == 'quarter') {timeRangeUnix = currentTimeStamp - 90*24*3600}
  if (timeRange == 'semi') {timeRangeUnix = currentTimeStamp - 180*24*3600}   
  // console.log("timeRange: "+timeRange);

  var lang = $("input[type='radio'][name='lang']:checked").val();
  // console.log("lang: "+lang);


  $.ajax({
            type: 'POST',
            url: '/searchEngine/search.php',
            data: {
                keyword: keyword,
                timeRange: timeRange,
                timeRangeUnix: timeRangeUnix,
                lang: lang,
            },
  });  


});

0 个答案:

没有答案