The goal of my project is a website that can show a list of addresses that updates without refreshing which means I have to use AJAX. I hope to include Javascript. the current code I have is the following:
<script src="https://code.jquery.com/jquery-3.1.1.min.js">
jQuery(document).ready(function ($) {
$('#get-data').click(function () {
var showData = $('#show-data');
$.ajax({
type: 'GET',
url: 'json.json',
})
})
})
while looking at the $.ajax() I’ve seen the data parameter often used but I have no clue what it’s purpose is or what I should insert into it. I’ve read multiple documentations yet I still don’t understand what I’m supposed to write in the data parameter. I’ve looked at different StackOverflow questions aswell but they haven’t brought me any further.
It’d be helpful if someone could help me with this. I’m having quite some problems just trying to figure out AJAX Calls in general.
2
Answers
From https://api.jquery.com/jquery.ajax/ :
Depending on your backend, you can then access this data while processing the request.
For example if your backend was Laravel (PHP) you could do:
And that would give you the data you passed in the ajax.
Here an example
If something goes wrong, always check the console