// Register the script
wp_register_script( ‘news-ticker’, get_template_directory_uri() . ‘/js/news-ticker.js’, array(‘jquery’), ‘1.0’, true );
// Localize the script with new data
$translation_array = array(
‘ajax_url’ => admin_url( ‘admin-ajax.php’ ),
‘json_url’ => ‘http://feeds.mse.mk/service/FreeMSEFeeds.svc/ticker/JSON/59c389c6-416d-4aeb-9f03-cc7a38b16533’
);
wp_localize_script( ‘news-ticker’, ‘news_ticker_data’, $translation_array );
// Enqueued script with localized data.
wp_enqueue_script( ‘news-ticker’ );
// Ajax callback
add_action( ‘wp_ajax_news_ticker_data’, ‘news_ticker_data_callback’ );
add_action( ‘wp_ajax_nopriv_news_ticker_data’, ‘news_ticker_data_callback’ );
function news_ticker_data_callback() {
$response = wp_remote_get( esc_url_raw( $_POST[‘json_url’] ) );
$data = wp_remote_retrieve_body( $response );
echo $data;
wp_die();
}