I currently have a job board on my site where users can put in a job title or keyword and a location to search for a job.
The results are displayed using Jquery/AJAX without a page refresh. However, I'd like to be able to link to the results for a specific search. For example, if I search for web development positions in OH, I'd like to be able to send a link to someone else who will be able to click on the link and go directly to the page with those results already loaded.
I have some knowledge of PHP but none of Ajax or Javascript/Jquery, which is why this is so hard for me. I'm hoping someone can help me with this.
Here's the code that is currently displaying the results:
jQuery(document).ready(function ($) {
// search button clicked
jQuery("input[name='indeedsearchbutton']").click(function () {
indeedsearchbusy();
indeedsearchcall();
})
// reset page if query changes
jQuery("input[name='q']").change(function () {
jQuery("input[name='start']").val(1);
})
// reset page if location changes
jQuery("input[name='l']").change(function () {
jQuery("input[name='start']").val(1);
})
if (autosearch) {
indeedsearchbusy();
indeedsearchcall();
}
})
// pagination set start position
function setstart(s) {
jQuery("input[name='start']").val(s);
indeedsearchbusy();
indeedsearchcall();
}
// get json data from inputs for ajax call
function getdata() {
var d = {
action: 'indeedcallback',
q: (jQuery("input[name='q']").length != 0 ? jQuery("input[name='q']").val() : jQuery("select[name='q']").val()),
l: jQuery("input[name='l']").val(),
start: jQuery("input[name='start']").val()
}
return d;
}
// display json results from ajax call
function indeeddisplayresults(resultsjson) {
var rpage = "";
if (resultsjson.pagination) rpage += resultsjson.pagination;
if (resultsjson.html) rpage += resultsjson.html;
if (resultsjson.pagination) rpage += resultsjson.pagination;
jQuery("div#indeedsearchresults").html(rpage);
}
// ajax call to search indeed
function indeedsearchcall() {
var data = getdata();
jQuery.post(wpajaxurl, data, function (response) {
resultjson = eval("(" + response + ")");
if (resultjson) {
indeeddisplayresults(resultjson);
}
})
}