In this code I have a normal dropdown where I have some city name. Now, what I actually want when I change any city then through jQuery I want to get JSON data in my alert box which is not working yet. I don't know why.
So, how can I do this?
Here is my code:
$(document).ready(function() {
$("#city").change(function() {
name = $(this).val();
console.log(name);
$.ajax({
type: "POST",
dataType: "json",
data: {
"name": name
},
url: "http://postalpincode.in/api/postoffice/" + name,
success: function(data) {
console.log(data);
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="city" id="city">
<option value="">Select City</option>
<option value="delhi">delhi</option>
<option value="ghaziabad">ghaziabad</option>
<option value="noida">noida</option>
<option value="meerut">meerut</option>
</select>
ERR_CERT_COMMON_NAME_INVALIDvar_dump($_POST);to make sure PHP is receiving the data.alert(data);doconsole.log(data);and check any data coming or not? (again check browser console tab)Mixed Content: The page at 'https://fiddle.jshell.net/_display/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://postalpincode.in/api/postoffice/noida'. This request has been blocked; the content must be served over HTTPS.https, then trying to load ahttpurl (http://postalpincode.in/api/postoffice/) will fail