The PHP part of your code looks more or less OK. (There are some security concerns and you shouldn’t echo an array of objects, but you’ll get it when you see it).
But your code doesn’t work because of an error in your JS.
You should send “action” as data and not as a setting… so it should look like this:
$.ajax({
url: my_ajax_object.ajax_url,
type: 'GET',
dataType: 'json', // added data type
data: {
action: 'getListings',
},
success: function(res) {
console.log(res);
}
});
Related Posts:
- What’s the preferred method of writing AJAX-enabled plugins?
- How to load wp_editor via AJAX
- Help with 4.6. Attachment response object in JSON API plugin
- How can I make an Ajax login form work with FORCE_SSL_ADMIN enabled?
- Help making my pagination plugin better
- admin-ajax returning 400 error when request is made with Fetch API
- How can I pass a variable to wp_ajax action?
- Loading shortcode with ajax
- How to pass JavaScript variable to PHP in wordpress widget?
- Add image to post from external URL
- How to add a sub menu with AJAX?
- AJAX Call Via Vanilla JavaScript In WordPress Plugin Development
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- jQuery AJAX call not executing in Plugin
- Create Proper WordPress Ajax Request in JavaScript, NOT jQuery
- Execute a function using ajax
- Problem running Ajax in WordPress
- Ajax Load More and Masonry: is it possible to load admin-ajax.php in the front end?
- How to save Clicks of a download link button while it doesn’t matter if we refresh the page or again login/logout
- ‘Lazy loading’ list of posts with pagination
- Errors while using ajax from external wordpress page
- I can’t access wordpress functions from an ajax php call
- Built in admin ajax hooks?
- How to include admin-ajax when loading external javascript
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- delete_user_meta Delete one value out of array
- How to use wp-ajax in wp-cron
- Calling shortcode in wp_localize_script strips result
- Why is my ajax call refreshing the page?
- What’s the point of using WordPress’s built in admin-ajax.php?
- Admin-ajax.php is dying “0” without processing function
- how to use ajax to display from database and load more in wordpress plugin
- How to remove an Ajax action
- How to create popup same as wordpress popup feature
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- Get Plugin Information from Multiple Sites Externally
- Ajax with jQuery UI dialog not working
- Shortcode in AJAX popup
- How to add pagination to wpbakery grid?
- How can I process xml file on upload?
- How can I reuse the WordPress search form for a custom plugin / widget?
- AJAX image upload with a upload progress bar using media_handle_upload
- jQuery Plugin to use WordPress functions in AJAX request
- ajax front-end increment views on click
- $wpdb working with ajax but showing ajax error instead of success
- Javascript not working
- Ajax specific template not loading in replacement of index.php
- WordPress ajax not working in registration
- AJAX login without a plugin does not work. when add a action to function.php
- Ajax return 0 in plugin – ajax only used in wp-admin
- What’s the preferred method of writing AJAX-enabled plugins?
- AJAX doesn’t pass variables to the php function in the plugin
- using jquery serialize in ajax operation for plugin
- ajax request not returning the result
- How do I convince this button to do something when it is clicked?
- Like/Dislike Bar not working when updating
- display user input using ajax in wordpress
- Ajax, jQuery and WordPress
- Plugin constructor called multiple times
- Hyperlink to execute PHP
- How to get site homepage from plugin?
- Contact Form loaded with Ajax
- How to load a plugin when doing an Ajax call? [duplicate]
- Ajax Not Working If The Handler is Located Outside Plugin Submenu Page Function
- Build and ajax plugin not work
- WordPress plugin ajax post parameter
- admin panel save option with ajax
- Capturing POST data
- My AJAX API plugin isn’t working
- ajax sends data to plugin
- Pulling Advanced Custom Fields from other pages
- Trouble After Update, Removing Plugin
- Trouble Removing Plugin [closed]
- Response from Php File to Ajax is not getting sent
- Help me with my first very basic plugin
- Plugin Admin Page Ajax-Admin call returning 0, URL set correctly. Implemented localized scripts but did not fix it
- How to change response of admin-ajax request?
- Ajax not working for logged in users
- Load css classes after using ajax calls
- Advanced Ajax Page Loader and Masonry Grid
- How to create load more button without a plugin?
- How to make a rest style plugin?
- WordPress portfolio pagination on home page
- wordpress Ajax success doesn’t return the value
- Jquery post responses 500 error after some time and lastly an 503 error
- Ajax button “Load more” is not loading correct language version posts for logged out users
- Ajax Called in Plugin php file
- Ajax Load More stopped working (Plugin with repeater template, shows hidden Button)
- How do I call an action hook into wp_ajax hook callback function
- Inline AJAX script passing variables to PHP
- Select posts from list and add them in a new list
- wordpress admin-ajax bad request 400
- I am trying to add form using ACF plugin and acf_form() function, but my user fields dont show up properly
- Not applying update field (acf) in my plugin
- How to get wp_editor field content when it is inside a Form?
- What is the best way to ignore wordpress administration using add_filter($title) also when Ajax request
- Ajax response from Media Selection does not update ALL information more than once
- Simple ajax request with Vanilla JS keeps given 400 Bad Request
- How to ajaxify all pages of my Wp Site
- Shipping Refund via Stripe Creates New Order Instead of Updating Original Order