Is it possible to make an ajax request inside another ajax request? because I need some data from first ajax request to make the next ajax request.
I tried to make a script, but i see that instead of GET, my request is POST and i dont know where is the problem..
JavaScript
x
37
37
1
<script type="text/javascript">
2
$.ajaxSetup({
3
headers: {
4
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
5
6
}
7
});
8
$('#file-upload').submit(function(e) {
9
e.preventDefault();
10
let formData = new FormData(this);
11
$('#file-input-error').text('');
12
$.ajax({
13
type: 'POST',
14
url: "{{ route('resume.store') }}",
15
data: formData,
16
contentType: false,
17
processData: false,
18
success: (response) => {
19
if (response) {
20
this.reset();
21
$("#showResponseArea span").html(response); //you will paste your response msg to the
22
$.ajax({
23
type: 'GET',
24
url: "{{ route('resume.api') }}",
25
dataType: 'json',
26
data: {
27
'url': response,
28
}
29
})
30
}
31
},
32
error: function(response) {
33
$('#file-input-error').text(response.responseJSON.message);
34
}
35
});
36
});
37
</script>
Advertisement
Answer
My code works perfectly, the real problem was in the controller, instead of:
JavaScript
1
10
10
1
public function fetch(Request $request)
2
{
3
$cvupload = $request->url;
4
$client = new Client();
5
$res = $client->get("https://api.apilayer.com/resume_parser/url?url=$cvupload", [
6
'headers' => [
7
'apiKey' => 'xxx'
8
]
9
]);
10
my code was with $res = $client->post
.