AJAX admin Internal 500 error Failed to Upload
UPDATE: After I saw an error massage it’s all because unsupported operand type error. $sum += $marks; its because store wrong type of value, I change to $sum->marks;
UPDATE: After I saw an error massage it’s all because unsupported operand type error. $sum += $marks; its because store wrong type of value, I change to $sum->marks;
You were using action to enqueue script, instead you need to use filter hook. As, you are adding a new script to the scripts call. However, if you used action hook for the wp_head call it works there. <?php add_filter(‘wp_enqueue_scripts’, ‘colorboxJS’); function colorboxJS() { wp_enqueue_script( ‘colorbox’, get_stylesheet_directory_uri() . ‘/colorboxJSfile.js’, array(‘jquery’) ); } ?>
If you search WordPress core for < or > you will find the function _wp_specialchars in /wp-includes/formatting.php Then if you search for _wp_specialchars you will see it is used in esc_js (as well as esc_html and esc_attr) so do not use esc_js, escaping is mostly for output anyway. Further search results show that in /wp-includes/default-filters.php … Read more
As I said in the comments. The problem was on api side. Error: (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). How to solve: Add this to .htaccess of api <IfModule mod_headers.c> Header set Access-Control-Allow-Origin: myUrl </IfModule>
Try & paste this below code your active theme functions.php file add_action( ‘wp_enqueue_scripts’, ‘load_jquery_fix’, 100 ); function load_jquery_fix() { if ( ! is_admin() ) { wp_deregister_script( ‘jquery’ ); wp_register_script( ‘jquery’, ( “//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js” ), false, ‘1.11.3’ ); wp_enqueue_script( ‘jquery’ ); } }
you are return simple a string in response variable that is not legitimate on the next line you are returning wp_send_json expect an array but you pass a variable.
You can get the time offset from WordPress Settings using get_option( ‘gmt_offset’ ) So I found the easiest method is to do this: gmdate( ‘Y-m-d H:i:s’, strtotime( get_option( ‘gmt_offset’ ) . ‘ hours’, strtotime( $udata->user_registered ) ) )
You need to use the wp_footer action hook, similar to this add_action(‘wp_footer’, ‘add_my_script’); function add_my_script() { ?> <script> // your script code here </script> <?php return; } This hook will hook into the themes’ wp_footer() call, so it will happen as part of the theme’s display of the footer. Place this code in the functions.php … Read more
Finally found the problem. The action: save_post was missing from data in ajax call. This code works: <script> jQuery( document ).ready(function() { jQuery(‘input[type=button]’).on(‘click’, function() { var ajaxurl = “<?php echo admin_url(‘admin-ajax.php’); ?>”; jQuery.ajax({ type: “POST”, data: { data:jQuery(‘.event-form’).serialize(), action: ‘save_post’ }, url: ajaxurl, success: function(result) { console.log(‘data sent!’); console.log(‘sent to: ‘ + templateDir + loadUrl … Read more
WordPress provides a list of the scripts they enqueue in the Codex. That’s a good place to start. Take a look at this question for a more complete answer: How can I get a list of all enqueued scripts and styles?