weixin_33725722 2017-06-08 12:44 采纳率: 0%
浏览 62

ajax在localhost上不起作用

I have a simple Ajax calculation but it doesn't work

that's the JavaScript Code

<script>


   function showFees() {
        e.preventDefault();
        var weight = ('weight').val;
        var ship_type== ('ship_type').val;
        var eol== ('eol').val;
        if (weight == 0) {
            document.getElementById("txtHint").innerHTML = "";
            return;
        } else {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
         document.getElementById("txtHint").innerHTML =this.responseText;
                }
            };
            xmlhttp.open("GET", "sdr.php?weight=" + weight "ship_type" + ship_type + "eol" + eol, true);
            xmlhttp.send();
        }
    }

that's my form

<form>

 <label>weight:</label> 

 <input type="number" name="weight" min="0" value="0">

 Ship Type:

 <select name="ship_type">

        <option value="1">Tankers of Crude Oil</option>
        <option value="2">Tankers of Petroleum Products</option>

      </select>
      Laden Or Ballast: 
      <select name="eol">
                <option value="0">Ballast</option>
                <option value="1">Laden</option>
              </select>   
      <input type="submit" onclick="showFees()" value="calc">
      </form>
      <p>Suggestions: <span id="txtHint"></span></p>

and my sdr page to calculate the final result

$weight;
$i=0;
$wpt=0/*weight per ton result*/;
$ship_type;
$eol;/*empty or loaded*/
$channel_weights=array(5,5,10,20,30,50,10000);

$weight = $_REQUEST['weight'];
$ship_type = $_REQUEST['ship_type'];
$eol = $_REQUEST['eol'];
while($weight!=0){
    if($weight>=$channel_weights[$i]){
        $wpt+=$channel_weights[$i]*$ship_load_vlues[$eol][$ship_type][$i];
        $weight-=$channel_weights[$i];
    } 
    else{
        $wpt+=$weight*$ship_load_vlues[$eol][$ship_type][$i];
        $weight=0;
    }

    $i++;
}

$final = $wpt*$float_sdr*1000;
echo $final === "0" ? "wrong data" : $final;
 ?>

I think echo must return to span with ID 'txtHint' but it doesn't return any and if I tried to put alert in java script doesn't work either and I tried to add ajax library and doesn't work also

  • 写回答

3条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 将位图选入内存DC失败,但没有出错信息
      • ¥15 c#调用soap出错,soapui中可以
      • ¥100 CBIS-DDSM kaggle 资料处理
      • ¥30 python 在 excel 用 OpenPyXL 怎么实现以下代码
      • ¥15 pywinauto 无法捕获到元素
      • ¥15 ARfoundation (可能由于没打开摄像头的)黑屏问题
      • ¥15 C++类模板继承模板本身,有偿
      • ¥15 pycharm打包项目包含mp3文件,运行exe程序后mp3文件没有执行。
      • ¥15 Quantlib求discount factors
      • ¥15 JS宏提取满足比率的字符区段