简体   繁体   中英

alert not working not showing up

I've input some code so that I can measure the current temperature of a location. I have the script which allows my user to check the location but the alert is not working.

<h3> Weather Data </h3>

<form method="POST" action="about.php">
    <input type="text" name="city" value= 'city'/>
    <input type="submit" name="submit" value="submit" />
</form>
<?php
    $city=$_POST['city'];
    var_dump($city);
?>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

<script>
    jQuery(document).ready(function($) {
        $.ajax({
          url : "http://api.wunderground.com/api/5e8af95dbdebbd73/geolookup/conditions/forecast/q/UK/<?php echo $city; ?>.json", 

          dataType : "jsonp",

          success : function(parsed_json) {
              var location = parsed_json['location']['city'];
              var temp_f = parsed_json['current_observation']['temp_f'];
              alert("Current temperature in " + location + " is: " + temp_f);
          }
        });
    });
    ?>
</script>

The alert should be appearing but nothing is am I doing something wrong.

You have an unnecessary closing php tag before your closing script tag:

 }
 });
  });
  ?> // this is a problem!
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM