I created this ajax file. I just want to know if there is a way to load the ajax file before i type in something. This file is only to test the ajax. When u run it the html display only the search bar. if i type something it print the typed stuff of the search bar and the var second. But i want that the html file displays it from beginning and the var will change later in the final file. is there a way to run the ajax once when I open up the page and not when i start typing?
I want to print the saved var(in this case second) when i open up the page or press f5. So when i open up the page it should print out: abcd
because the variable already exist(again it is var second)
I want that the function 'keyup(function()' run on beginning to show the results of the hardcoded string
$(document).ready(function(){
$("#search_text").keyup(function(){
var search = $(this).val();
var second = "abcd";
$.ajax({
url:'checkvalues.php',
method:'post',
data:{query:search, second:second},
success: function(resonse){
$("#result").html(resonse);
}
})
})
})
if(isset($_POST['query'])){
echo $_POST['query'];
}
if(isset($_POST['second'])){
echo $_POST['second'];
}
?>