contentType
is the HTTP header sent to the server, specifying a particular format.
Example: I’m sending JSON or XMLdataType
is you telling jQuery what kind of response to expect.
Expecting JSON, or XML, or HTML, etc. The default is for jQuery to try and figure it out.
The $.ajax()
documentation has full descriptions of these as well.
In your particular case, the first is asking for the response to be in UTF-8
, the second doesn’t care. Also the first is treating the response as a JavaScript object, the second is going to treat it as a string.
So the first would be:
success: function(data) { // get data, e.g. data.title; }
The second:
success: function(data) { alert("Here's lots of data, just a string: " + data); }
Related Posts:
- what does jQuery data() function do
- Jquery change background color
- TypeError: $.ajax(…) is not a function?
- jQuery Toggle Text?
- How do I select multiple fields in jq?
- jQuery – replace all instances of a character in a string [duplicate]
- jQuery how to find an element based on a data-attribute value?
- Display XML content in HTML page
- jQuery: outer html()
- How to change the text of a button in jQuery?
- jquery – is not a function error
- jQuery: outer html() [duplicate]
- Play/pause HTML 5 video using JQuery
- jQueryUI dialog width
- jQuery Form Validation before Ajax submit
- How to use date picker in Angular 2?
- $(document).ready(function() is not working
- Using OR operator in a jQuery if statement
- Resource interpreted as Document but transferred with MIME type application/json warning in Chrome Developer Tools
- Animate element transform rotate
- Is jQuery included in WordPress by default?
- Using jQuery to delete data stored in wp_options
- Creating Multiple wp_localize_script for Shortcode?
- Making $ globally accessible with jQuery.noConflict()
- Color Picker (iris) in widget – refresh when edited in Customizer
- Ajax call does not activate callback function
- Add `datetimepicker` to form
- How to reload a select box of posts dynamically?
- How to pass both action and formdata in wordpress ajax?
- Script dependencies for post.js
- How wp_enqueue_script works?
- Can’t move jQuery to footer
- Get specific image size for small viewport width
- Using jQuery to retrieve customizer value
- wp_ajax unauthenticated and authenticated
- WordPress ajax function parameter value not being passed
- Is it safe to include a javascript file in a template’s php file?
- Firebug : Problem with jQuery in WordPress admin panel
- JSON output returns page source code [closed]
- Display data on same page as form without refresh
- Masonry and Jetpack Infinite Scroll – overlap issue
- Dealing with a library that depends on jQuery
- How can I load jquery library into my dashboard widget?
- Accessing user Meta data via REST and backbone
- Gravity Forms – jQuery in List Field [closed]
- Help with a jQuery Carousel
- Passing a varible from jQuery to PHP
- Vanderlee jQuery color picker and WordPress Errors
- Retrieve post info within AJAX helper function
- Fall Back Google CDN in JavaScript
- wp_enqueue doesn’t work
- Gutenberg – Title field required
- WP-admin redirects to login after adding SSL certificate
- Dynamicaly update field created with wp_editor()
- Adding a slide toggle on WordPress
- add custom HTML css with js doesn’t work
- Change quantity via jQuery and disabile quantity field [closed]
- Get value of selected option in select field in a WordPress form
- How to retrieve WP_Object that is inside an array of another array
- jQuery – Toggle megamenu submenu items by click
- General Settings: display custom plugin field after Site Address field
- WP Customizer: Save a control state
- WordPress Insert not working with ajax
- WP AJAX API with JS file
- need to override function in jquery.ui.datepicker.js
- Dynamic WordPress editor in meta box
- Getting jQuery AJAX to work in WordPress (getting -1)
- How to wrap posts into divs?
- jQuery Drill Down iPod Menu FOUC and Selecting Current page
- Absolute path to stylesheet_dir/images/my_img.jpg does not work?
- Which hook to use when adding ajax to viewer-facing side?
- WordPress and Modal Popup – how to make the already loaded javascript assets available in modal?
- jquery.min has very long TTFB
- animate.style on wp-login.php
- Theme style overrides the plugin style
- Form validation before submitting
- bundled jquery in theme js not working with wp_localize_script
- Special Characters and Spaces are not transferred correctly via AJAX call.
- How to manipulate elements on the Insert Media Attachment settings popup
- Site images are fixed in front of my site content [closed]
- How to toggle custom WP archive list
- I can’t enqueue Suggest.js in frontend – not added
- Jquery code won’t run loaded from WP, but run from console
- JQuery is not defined but jquery script is loaded in source [closed]
- jQuery post method in admin menu
- jQuery AJAX add json2 dependency?
- Running javascript in a child theme. Works in jsfiddle
- How to block action if post is “dirty”?
- $ not defined using jQuery in WordPress
- How to read the contents of single post through RSS feed
- jQuery Ajax / Modal admin event not firing since 3.6. Seems to not recognize “a” tag
- Auto Select Child categories on Multiple Dropdown – Jquery
- adding the full image path to a wordpress javascript file
- jQuery Live Form Validation in WordPress
- Ensure an external javascript file called from plugin is loaded after jquery is called
- jQuery not working for tabs shortcode [closed]
- Why my vertical tab js code is refreshing the page continuously? [closed]
- bootstrap-slider.js by seiyria not working in wordpress
- Sliders with buttons [closed]
- jQuery datepicker not showing on admin menu