Skip to content

Instantly share code, notes, and snippets.

@NickDeckerDevs
Created July 27, 2018 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickDeckerDevs/44a1094849af74ae2ccdf658255f04b6 to your computer and use it in GitHub Desktop.
Save NickDeckerDevs/44a1094849af74ae2ccdf658255f04b6 to your computer and use it in GitHub Desktop.
example jQuery to contact our wordpress site and bring in our menu into our hubspot template
// I place this inside window.load so that the page gets moving and then the header gets brought in.
// you can change the cache to true
// you can do a lot more with this. Once you get a working version of this you will begin to think about
// all the ways you can play with this
$(window).load(function() {
$.ajax({
type : 'GET',
url : 'http://www.domain.com/primary-menu', // make sure this is the url of your menu page you created
dataType : 'html',
cache: 'false',
success : function(data){
// this is the div we are going to place our menu into. Make sure this is changed below
// data is the content of your page. You can get more advanced on this by parsing and doing
// some other stuff with the data.
$('#js-insert-primary-menu').html(data);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
// I leave some sort of error here so that I can immediatly understand what is the issue
// you might want to remove this stuff and only have a console message to contact developer
// or whatever
$('#js-insert-primary-menu').html('There was an error, please check console');
console.log(errorThrown);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment