You need a die(); before the closing } of the function and you might want to add the relevant php header to tell the browser it’s content-type
I wouldn’t worry about the browser returning the wrong content type.
As long as your code loading the data treats it as JSON
So for your function try this instead
function ajax_return_catalog_info() {
header('Content-type: application/json');
switch($_REQUEST['fn']) {
case 'ajax_call_1':
// do ajax method 1 here
echo json_encode($output);
break;
case 'ajax_call_2':
// do ajax method 2 here
echo json_encode($output);
break;
}
die();
}
if you don’t die you get a 0 stuck on the end as well, as it collapses back to the Ajax Call Function (which goes echo 0;die();
Related Posts:
- Is there a JavaScript API? How to access public and private data in JS?
- Delete row of custom table in WordPress using AJAX
- AJAX request from Chrome Extension to WordPress Website
- fetching via fetch/ajax gutenberg block data from third party
- wp_localize_script escaping my url – fix or alternative
- Most performant way of fetching remote API data?
- How to add WP API and JS featured image attachment
- Implementing an AJAX POST API call in wordpress
- I have to post data by AJAX in wordpress to another Website
- Why Does WordPress not output admin-ajax.php path by default?
- Save & Reset button in theme-option with Ajax (without refresh)
- Use WP admin AJAX url to hide API key
- Retrieve JSON file from JS trough php
- How can I call an api before user login
- mailchimp integration on a custom footer
- Jquery wrap permalink in a data-attribute?
- AJAX save options inside class
- register_setting and AJAX?
- How to submit a button automatically after every scheduled hours?
- Refresh HTML Page in Browser Automatically on Timer – Every 15 Min
- How to load wp_editor() through AJAX/jQuery
- How to get a unique nonce for each Ajax request?
- Open a Thickbox with content trough AJAX
- failed to load wp-admin/admin-ajax.php
- Are ‘wp_ajax’ and ‘wp_ajax_nopriv’ exclusive to authenticated and non-authenticated users?
- How to HTML5 FormData Ajax
- Get posts with ajax
- Ajax requests without JQuery
- WordPress AJAX Login Screen
- Custom PHP endpoint for a plugin’s AJAX call
- How to link WordPress heartbeat to ajax form
- How can I get logged in user’s session data from admin-ajax?
- WordPress Ajax Login without page reload
- AJAX only works when I’m logged as Admin
- When using javascript to dynamically add a textarea, how can I render it as a tinyMCE editor (in wordpress)?
- How do I create a widget that only allows a single instance?
- Drag and drop multiple file upload using Ajax WordPress
- Custom ordering fails after AJAX post filter
- How to securely add an Ajax button to a WP Admin page?
- How to “Load More” posts via AJAX?
- Issue with front-end ajax, getting a 302 redirect when accessing wp-admin/admin-ajax.php
- REST-API: extend media-endpoint
- Prevent page reload after ajax form submission
- WordPress Ajax Getting Response “Null”
- Custom Login and Registration form in Ajax
- admin-ajax return error 400 for Chrome/Edge but not Firefox
- Is it safe to manually sign a user in using AJAX?
- WordPress Admin AJAX Serialize
- My ajax code not returning ajax value
- register ajax calls hook
- Why a strange discrepency between get_current_user_id() when using AJAX versus output of document.cookie?
- Loading post template that contains a nested loop with ajax
- Long Polling: Stuck in while loop
- Show Post Content with AJAX
- What’s the best way to implement AJAX in WordPress?
- How to add AJAX in a custom PHP function using Google sheets API
- Code run fast on a cronjob but slow with a do_action or ajax call
- update_post_meta using ajax
- How to export custom database data to excel file
- Ajax comment form submit on frontpage alerts success but no insertion
- How to update Comment post meta through an Ajax call
- ModSecurity && Admin Ajax: Server locking up
- Wp mail does not work when Ajaxed to
- How to pass parameters from jQuery ajax into PHP function?
- ajax is returning 0
- How to add ajax url to js using wp_add_inline_script()?
- WP AJAX post filter > do something with empty value
- How to make a fetch() POST request to wordpress rest api?
- How to jQuery Ajax show new data from successful insert?
- Adding tags when creating new post
- ajaxt returning object object [closed]
- Why is the file not uploading to the server?
- Get localize of a loaded javascript
- is there’s a way to get the next page content generated by page break block with ajax call?
- Query data after an Ajax insert
- How to get next and previous post into ajax formed modal windows?
- Passing value from select form with Ajax not working
- Sending email through Ajax without page refresh hangs on admin_ajax.php
- Why Ajax Doesn’t Work?
- Problem when sending file via ajax
- wp_verify_nonce not working on the mobile device
- Frontend AJAX Media Upload returning 404
- Using AJAX to submit and return data inside the WordPress Plugin Boiler Plate framework
- Change button text after ajax db update
- How to implement AJAX within a class storing shortcode atts as class variables
- How do I display posts of a specific day?
- (Frontend AJAX) get post data WITH image thumbnail?
- Native WordPress Video Shortcode Not Working After Post is Loaded via Ajax
- Ajax Function call is always returning 0 in front end(without plugin) [closed]
- Ajax live search, “No products found” when the title contains apostrophes and quotations
- Add Ajax loaded posts to existing posts
- Speeding up admin-ajax.php
- admin ajax is not working for non logged in users
- Change search to outpout category name instead of Post type name
- ‘Dehighlighting’ navigation once clicked
- wp_localize_script not create variable in head section
- wordpress ajax bad request 400
- JQuery UI Autocomplete/Autosuggest WordPress
- Object name undefined using localize script
- Help with jquery/ajax requests