Cross-Domain Ajax request
-
Hi everybody. I try to send an ajax-request to a different server than where my wordpress installation is hosted. This site returns a xml file which I need to process.
So this is the originial form how to snd things to the provider:
<h3>Step 2: XML authorizeSplit (server-2-server request)</h3> <form action="https://.../file.jsp" method="post" target="_parent"> <fieldset> <textarea style="width: 400px; height: 150px;" name="xmlRequest" id="xml-request"></textarea> <div> <input type="submit" class="button" value="send" id="submit_payment" /><span class="buttend"></span> </div> </fieldset> </form>So I reformulated this into a typical wordpress ajax call:
jQuery Code:
$('#step2 #submit_payment').click(function() { var xmlRequest = $('#step2 #xml-request').val(); var ajax_url = $('#step2').find('input[name="ajax_url"]').attr('value'); $.ajax({ type: 'POST', data: 'action=redirect_to_external&xml_request=' + xmlRequest, url: ajax_url, //async: false, beforeSend: function() { // display loading animation container }, error: function(responseData, textStatus, errorThrown) { alert(textStatus); }, success: function(data) { alert(data); } }); });PHP function the ajax request refers to:
function redirect_to_external() { $xml_request = $_POST['xml_request']; header("Location: https://.../file.jsp?xmlRequest=".urlencode($xml_request)); } add_action('wp_ajax_redirect_to_external', 'redirect_to_external'); add_action('wp_ajax_nopriv_redirect_to_external', 'redirect_to_external');So the callback is always giving me an error. But in general the ajax call works locally. In case I replace the header statement inside my php function and just echo some text, this is returned. So my question is how can I send my xml request to the external server. Is there any chance to do it this way or do I have to setup a proxy functionality or something else?
Any hints are very welcome.
Thanks in advance.Cheers, kool
The topic ‘Cross-Domain Ajax request’ is closed to new replies.