gpt4 book ai didi

javascript - 又是Safari??表单提交绕过 AJAX

转载 作者:行者123 更新时间:2023-12-03 08:51:10 26 4
gpt4 key购买 nike

我的大脑快爆炸了 - 无法弄清楚 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.
}
});

关于javascript - 又是Safari??表单提交绕过 AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32664946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com