我的大脑在爆炸-无法找出Safari的问题所在。所有浏览器都可以正常工作,但是Safari根本无法读取我的JavaScript。甚至不是一个简单的“ alert()”。有什么线索吗?

============ HTML ===============
        

</div>

<div class="container top">

    <h1 class="text">Weather Dashboard</h1>

    <h3 class="text">Enter the city to get a 3-day forecast</h3>


    <form id="cityForm" class="form-group">
        <div class="container-fixed">
            <div class="form-horizontal">

                    <div class="input-group inpWid">
                    <div class="input-group-addon">
                        <span class="glyphicon glyphicon-home"></span>
                    </div>
                        <input type="text" class="form-control" id="city"
                            name="city" placeholder="Enter the City">
                    </div>

                <button type="submit" class="btn btn-primary btn-success">Weather Me!</button>
            </div>
        </div>
    </form>

<div class="container-fixed" id="weatherBox">

</div>

</div>


============ jQuery / JavaScript ===============

$("#cityForm").submit(function(e) {
    e.preventDefault();
    alert("safari");
    var url = "scraper.php"; // the script where you handle the form input.
    var city1 = $("#city").val();
    var city = city1.replace(/\s+/g, '');

    $.ajax({
          type: "POST",
          url: url,
          cache:false,
          data: {city, city1},
          success: function(data){
                 $("#weatherBox").html(data); // show response from the php script.
          }
    });

    return false; // avoid to execute the actual submit of the form.
});


============ PHP ===============

        $city = $_POST["city"];
        $city1 = $_POST["city1"];
        $url="http://www.weather-forecast.com/locations/$city/forecasts/latest";
        $content = file_get_contents($url);

        preg_match('/3 Day Weather Forecast Summary:<\/b>(.*?).<\/span>/s', $content, $day1);
        preg_match('/7 Day Weather Forecast Summary:<\/b>(.*?).<\/span>/s', $content, $day2);
        preg_match('/10 Day Weather Forecast Summary:<\/b>(.*?).<\/span>/s', $content, $day3);

        for ($i=1; $i<=3; $i++) {

            ${d.$i} = '<img src="sun.gif" alt="sun" height="42" width="42">';

            $wCon = ${day.$i}[1];
            preg_match("/dry/i", $wCon, ${weather.$i});

            if (${weather.$i}[0]!="dry"){
                ${d.$i} = '<img src="rain.png" alt="rain" height="42" width="42">';
            };

            unset(${weather.$i}[0]);
        };


============网站===============

http://alexanderii.net/cover/

最佳答案

您有语法错误:-
 将data: {city, city1},更改为data:{'city':city,'city1':city1}
  试试这个代码:

 $.ajax({
      type: "POST",
      url: url,
      cache:false,
      data:{'city':city,'city1':city1},
      success: function(data){
             $("#weatherBox").html(data); // show response from the php script.
      }
});

09-11 19:10