Reputation: 4565
success: function (data) {
if(data=='alreadysubmit')
{
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function()
{
alert("hi");
});
}
else{
$("input:checked").next().text('Votes:'+data);
}
}
what above is a snippet of my code, which is supposed to load Google Visualization APT,in the javascrpit draw.js. The draw.js is somewhere else in my local drive and I thought I can trigger it in the $.getScript function because in the draw.js there are some functions that I need to use for the current page. btw, the alert("hi") did take effect and the page kept loading... Am I supposed to do this? the idea is that I want to use draw.js only if the condition is met,if(data=='alreadysubmit'). Thank you in advance.
Upvotes: 0
Views: 67
Reputation: 385194
Multiple lines inside a conditional block must be surrounded by {
and }
.
So:
if (data=='alreadysubmit')
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function() {
alert("hi");
});
becomes:
if (data=='alreadysubmit') {
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function() {
alert("hi");
});
}
Your snippet fully corrected in this regard:
if (data == 'alreadysubmit') {
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function() {
alert("hi");
});
}
else {
$("input:checked").next().text('Votes:'+data);
}
Upvotes: 0
Reputation: 2180
success: function (data) {
if(data=='alreadysubmit'){
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function()
{
alert("hi");
});
}else{
$("input:checked").next().text('Votes:'+data);
}
}
This?
Upvotes: 1