Update URL Bing API

by Chris Vitalos

HTML

<button onclick='requestWithoutAjax("https://ssl.bing.com/webmaster/api.svc/pox/SubmitUrl?apikey= 27aedaeb929d4345b55085ff90be6ccb", {"siteUrl":"https://www.washborodems.org","url":"https://www.washborodems.org/home","url":"https://www.washborodems.org/josephine-noone","url":"https://www.washborodems.org/sonia-ron","url":"https://www.washborodems.org/chris-bauknight","url":"https://www.washborodems.org/follow-us","url":"https://www.washborodems.org/about-us","url":"https://www.washborodems.org/privacy","url":"https://www.washborodems.org/terms"})'>Make post call</button>

JavaScript

/**
* Make a request without ajax and without refresh the page
* Invisible for the user
* @param url string
* @param params object
* @param method string get or post
**/
function requestWithoutAjax( url, params, method ){
    
    params = params || {};
    method = method || 'post';

    // function to remove the iframe
    var removeIframe = function( iframe ){
        iframe.parentElement.removeChild(iframe);
    };
    
    // make a iframe...
    var iframe = document.createElement('iframe');
    iframe.style.display = 'none';
    
    iframe.onload = function(){
        var iframeDoc = this.contentWindow.document;
        
        // Make a invisible form
        var form = iframeDoc.createElement('form');
        form.method = method;
        form.action = url;
        iframeDoc.body.appendChild(form);
        
        // pass the parameters
        for( var name in params ){
            var input = iframeDoc.createElement('input');
            input.type = 'hidden';
            input.name = name;
            input.value = params[name];
            form.appendChild(input);
        }
        
        form.submit();
        // remove the iframe
        setTimeout( function(){ 
            removeIframe(iframe);
        }, 500);
    };
    
    document.body.appendChild(iframe);
}