I have a problem in Ajax.
My JS File:
$(document).ready(function() {
$(document).ajaxStart(function() {
$("#wait").css("display", "block");
});
$(document).ajaxComplete(function() {
$("#wait").css("display", "none");
});
$("button").click(function() {
$.post("ajax", {
name: "Donald Duck",
_token: "{!! csrf_token() !!}",
city: "Duckburg"
},
function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
});
});
my html code:
<div id="wait" style="display:none;width:69px;height:89px;border:1px solid black;position:absolute;top:50%;left:50%;padding:2px;">
<img src='demo_wait.gif' width="64" height="64" />
<br>Loading..</div>
<button>Start</button>
And it works fine , I need passing a value from button code to Javascript, which I then use for the Post URL.
I changed the js file to:
function MyJS(str) {
$(document).ready(function() {
$(document).ajaxStart(function() {
$("#wait").css("display", "block");
});
$(document).ajaxComplete(function() {
$("#wait").css("display", "none");
});
$("button").click(function() {
$.post("ajax" + str, {
name: "Donald Duck",
_token: "{!! csrf_token() !!}",
city: "Duckburg"
},
function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
});
});
}
and my new html code is:
<div id="wait" style="display:none;width:69px;height:89px;border:1px solid black;position:absolute;top:50%;left:50%;padding:2px;"><img src='demo_wait.gif' width="64" height="64" /><br>Loading..</div>
<button onclick="MyJS('9');">Start</button>
After the changes, the code seems to stop working.