I don't know what is wrong with my code. I tried to fill javascript prompt with ajax response. Here is my code :
$.ajax({
url: "{{ url('/dashboard/popfieldexist') }}",
dataType: "json",
type: 'POST',
data: "_token={{ csrf_token() }}&"+"selector="+f1[0].getAttribute('data-file'),
success: function (response) {
if(response){
getPopfield = response.data.field;
}else{
getPopfield = " ";
}
}
});
var title = prompt("File name : ", ""+getPopfield+"");
it display undefined..
An ajax call is usually asynchronous. So your prompt is called before the ajax finished.
Try:
$.ajax({
url: "{{ url('/dashboard/popfieldexist') }}",
dataType: "json",
type: 'POST',
data: "_token={{ csrf_token() }}&"+"selector="+f1[0].getAttribute('data-file'),
success: function (response) {
if(response){
getPopfield = response.data.field;
}else{
getPopfield = " ";
}
var title = prompt("File name : ", ""+getPopfield+"");
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.