Reputation: 740
i can't find what's wrong
1- a city is working fine
and 2- empty is working fine
3- not a city isn't working id #not2
@JS
<script>
$("#find").click(function(event){
$(".alert").fadeOut();
event.preventDefault();
if($("#Wcity").val()!=""){
$.get("PHP/wS.php?Wcity="+$("#Wcity").val(),function(data){
if(data==""){
$("#not2").fadeIn();
}else{
$("#FC").html(data).fadeIn();
};
});
}else{
$("#not").fadeIn()
}
});
@html
<form>
<input id="Wcity" type="text" placeholder="Eg. Tokyo , london , Alexandria">
<input id="find" type="submit" value="Find My City">
</form>
<div id="not" class="alert">please enter a city</div>
<div id="not2" class="alert">Could not find weather data for the city, Try again</div>
<div id="FC" class="alert"></div>
<span id="me">created by Nrome ,uses weather-forecast.com</span>
hank for your help
Upvotes: 0
Views: 30
Reputation: 1533
Ah, the problem is that your PHP call is not returning success, so therefore your success function is not even getting called. You need to specify a "failure function" that gets executed whenever the PHP call fails.
See the jQuery docs for how to specify your failure function.
Here's what I would do:
$("#find").click(function(event){
$(".alert").fadeOut();
event.preventDefault();
if($("#Wcity").val()!=""){
$.get("PHP/wS.php?Wcity="+$("#Wcity").val(),function(data){
if(data.trim()==""){
$("#not2").fadeIn();
}else{
$("#FC").html(data).fadeIn();
};
})
.fail(function() {
$("#not2").fadeIn();
});
}else{
$("#not").fadeIn()
}
});
Upvotes: 1