WordPress Ajax Getting Response “Null”

I am trying to get ID of post on HOME page .So far my coding is wp_enqueue_script( ‘my-ajax-request’, get_stylesheet_directory_uri() . ‘/js/ajax.js’, array( ‘jquery’ ) ); wp_localize_script( ‘my-ajax-request’, ‘MyAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); add_action(‘wp_ajax_nopriv_ajax_request’, ‘ajax_handle_request’); add_action(‘wp_ajax_ajax_request’, ‘ajax_handle_request’); function ajax_handle_request(){ $postID = $_POST[‘id’]; if (isset($_POST[‘id’])){ $post_id = $_POST[‘id’]; }else{ $post_id = “”; } … Read more

Prevent page reload after ajax form submission

I’m trying to submit a form in wordpress with ajax. But after the first submision the page itself is called again. My Form <form class=”et_pb_contact_form clearfix” method=”post” action=”” id=”loginform”> <p class=”et_pb_contact_field et_pb_contact_field_0 et_pb_contact_field_last” data-id=”mail” data-type=”input”> <label for=”et_pb_contact_mail_1″ class=”et_pb_contact_form_label”>E-Mail-Adresse</label> <input type=”email” name=”mail” id=”mail” value=”” placeholder=”E-Mail-Adresse” required=””/> </p> <p class=”et_pb_contact_field et_pb_contact_field_1 et_pb_contact_field_last” data-id=”pw” data-type=”input”> <label for=”et_pb_contact_pw_1″ class=”et_pb_contact_form_label”>Passwort</label> … Read more

Ajaxing in functions.php

To ajax filtered posts, I needed to put most of my index.php template into the functions.php file (followed this tutorial) and do from there. But now javascript won’t work – basically the accordion style listings won’t open and close like they did before, trailers won’t embed, etc. Click on a tag to demo here. Is … Read more

WordPress Ajax callback function from plugin – OOP

Using PluginBoilerplate to write a plugin. I need to make an ajax call. I added to main plugin.php file, class to register scripts and handle ajax calls. if ( ! class_exists( ‘PoorMansNameSpaceAJAX’ ) ) { class PoorMansNameSpaceAJAX{ public static $instance = null; public $nonce=””; public $name=”ajaxexample”; public static function getInstance() { null === self::$instance AND … Read more

Getting $comments outside the comment template

I have a ajax request hooked on “template_redirect” (the ajax requests the post’s url), and I want to display only the comment template: function get_comm(){ if(isset($_GET[‘get_my_comments’])): $offset = intval($_GET[‘get_my_comments’]); echo $offset; // offset will be the same as “cpage” global $comments, $wp_query, $post, $id; print_r($comments); // nothing ? print_r($wp_query->comments); // nothing ?? wp_list_comments(‘type=comment’, $comments); // … Read more

What’s to stop malicious code from spoofing the “Origin” header to exploit CORS?

The way I understand it, if a client-side script running on a page from foo.com wants to request data from bar.com, in the request it must specify the header Origin: http://foo.com, and bar must respond with Access-Control-Allow-Origin: http://foo.com. What is there to stop malicious code from the site roh.com from simply spoofing the header Origin: … Read more

POST JSON fails with 415 Unsupported media type, Spring 3 mvc

I am trying to send a POST request to a servlet. Request is sent via jQuery in this way: var productCategory = new Object(); productCategory.idProductCategory = 1; productCategory.description = “Descrizione2”; newCategory(productCategory); where newCategory is function newCategory(productCategory) { $.postJSON(“ajax/newproductcategory”, productCategory, function( idProductCategory) { console.debug(“Inserted: ” + idProductCategory); }); } and postJSON is $.postJSON = function(url, data, … Read more