1๐
My guess is you submit your page.
Try this
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#some_id").on("click",function(event) {
event.preventDefault(); // cancel the event - not needed on type=button though
$.get("/some/url/", function(data) {
window.console&&console.log('hey');
});
});
});
</script>
</head>
<body>
<button type="button" id="some_id">Click</button>
</body>
</html>
this assumes the return value from /some/url/ is valid object โ the console should tell you
๐คmplungjan
0๐
The result is probably not in JSON format, so when jQuery tries to parse it as such, it fails. Try validating the JSON.
If the response is not in JSON format then try specifying the datatype. If it is returning a simple text then specify text
.
$.get("/some/url/", function(data) {
alert('hey');
}, "text");
๐คJRodDynamite
- Django filter object with list of values
- Django Test request.method == 'POST' not working
- Django select_related, prefetch_related. How to read django_toolbar?
- Django Forms Not adding objects to DB
- Large project files in Heroku on Django
0๐
Try to use the Promise mechanism:
$.get("/some/url/").done(function() {
alert( "1" );
})
.fail(function() {
alert( "2" );
})
.always(function() {
alert( "3" );
});
Also, you can use $.ajax() function to test if connection is correct
๐คgesiud
Source:stackexchange.com