Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX not working in IE in a Wordpress Plugin
    primarykey
    data
    text
    <p>I am building a Wordpress plugin and I am attempting to use AJAX. I am having trouble getting AJAX to work in IE.</p> <p>The following attempts all work in FF/Chrome but fail in IE.</p> <p>PHP:</p> <pre><code>add_action('wp_ajax_nonpriv_trying_ajax', 'trying_ajax'); add_action('wp_ajax_trying_ajax', 'trying_ajax'); function trying_ajax(){ $response = json_encode( array( 'success' =&gt; true ) ); header( "Content-Type: application/json" ); echo $response; exit; } </code></pre> <p>Javascript:</p> <pre><code>var ajaxData = { action: 'trying_ajax', state: filterStates }; JQuery.post(myconvio_convio_functions.ajaxurl, ajaxData, function(data) { alert(data); }, 'json' ); </code></pre> <p>FF/Chrome returns a JSON object; however IE returns a 0.</p> <p><a href="http://codex.wordpress.org/AJAX_in_Plugins" rel="nofollow">http://codex.wordpress.org/AJAX_in_Plugins</a> says...</p> <blockquote> <p>Error Return Values</p> <p>If the AJAX request fails when the request url is wp-admin/admin-ajax.php, it will return either -1 or 0 depending on the reason it failed. Additionally, if an AJAX request succeeds, it will return a 0.</p> </blockquote> <p>I have tried this to account for caching by:</p> <pre><code>var d = new Date(); var n = d.getTime(); JQuery.post(myconvio_convio_functions.ajaxurl+"?x="+n, ajaxData, </code></pre> <p>I have tried a relative url to account for cross domain issues:</p> <pre><code>JQuery.post('/FWW/wp-admin/admin-ajax.php', ajaxData, </code></pre> <p>All the same results: FF/Chrome returns a JSON object; however IE returns a 0.</p> <p>Thanks for any help.</p> <p>.... Changed to $.ajax and added success,error and complete - results are in the comments. Still the same results, IE comes back as success but with response of 0</p> <pre><code>$.ajax({ url: '/FWW/wp-admin/admin-ajax.php', type: 'POST', data: ajaxData, dataType: 'json', success: function(response, status, xhr) { console.log(response); // Firebug log: Object { success=true } alert('success - response: ' + response); // FF Alert: success - response: [object Object] // IE Alert: success - response: 0 alert('success - status: ' + status); // IE&amp;FF Alert: success - status: success alert('success - xhr.readyState: ' + xhr.readyState); // IE&amp;FF Alert: success - xhr.readyState: 4 alert('success - xhr.responseText: ' + xhr.responseText); // FF Alert: success - xhr.responseText: {"success":true} // IE Alert: success - xhr.responseText: 0 alert('success - xhr.status: ' + xhr.status); // IE&amp;FF Alert: success - xhr.status: 200 alert('success - xhr.statusText: ' + xhr.statusText); // IE&amp;FF Alert: success - xhr.statusText: OK }, // error handler function never gets called on IE or FF error: function(jqXHR, textStatus, errorThrown) { alert('error jqXHR: ' + jqXHR); alert('error textStatus: ' + textStatus); alert('error errorThrown: ' + errorThrown); }, complete: function(jqXHR, textStatus){ alert('complete - jqXHR.readyState: ' + jqXHR.readyState); // IE&amp;FF Alert: complete - jqXHR.readyState: 4 alert('complete - jqXHR.responseText: ' + jqXHR.responseText); // FF Alert: complete - jqXHR.responseText: {"success":true} // IE Alert: complete - jqXHR.responseText: 0 alert('complete - jqXHR.status: ' + jqXHR.status); // IE&amp;FF Alert: complete - jqXHR.status: 200 alert('complete - jqXHR.statusText: ' + jqXHR.statusText); // IE&amp;FF Alert: complete - jqXHR.statusText: OK alert('complete - textStatus: ' + textStatus); // IE&amp;FF Alert: complete - textStatus: success } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload