Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery cors ajax request failing
    primarykey
    data
    text
    <p>I'm trying to fire a cors ajax request with jQuery towards a different port in the same machine, below is my code (my application is running on an appache server on port 80):</p> <p>JS:</p> <pre><code>$(function(){ jQuery.support.cors = true; $.ajax({ type: "POST", url: "http://127.0.0.1:8080/sys_monitor/ccn", dataType: "text", contentType: "text/plain", data : {a: '11'}, success : function(res){ alert(res); $('#stage').html(res); }, error : function(jqXHR, text, exception){ if (jqXHR.status === 0) { alert ('Not connected.\nPlease verify your network connection.'); } else if (jqXHR.status == 404) { alert ('The requested page not found. [404]'); } else if (jqXHR.status == 500) { alert ('Internal Server Error [500].'); } else if (exception === 'parsererror') { alert ('Requested JSON parse failed.'); } else if (exception === 'timeout') { alert ('Time out error.'); } else if (exception === 'abort') { alert ('Ajax request aborted.'); } else { alert ('Uncaught Error.\n' + jqXHR.responseText); } } }); }); </code></pre> <p>Servlet ("post" is written to the console) running on tomcat (eclipse) on port 8080:</p> <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().write("hello there"); System.out.println("post"); } </code></pre> <p>using firebug I can see the request (with response code 200) and content length 11 (empty result tab), but the error function is being executed with XHR status 0 </p> <p>(side question1: why is firebug displaying "xml" as type ?):</p> <p>(side question2: why isn't there an OPTIONS request before the POST ?):</p> <p><img src="https://i.imgur.com/S1Q1XCn.png" alt="firebug"></p> <p>I also tried with RESTClient plugin for firefox, and I'm getting the wanted result:</p> <p><img src="https://i.imgur.com/wqzTj6t.png" alt="RESTClient plugin"></p> <p>all help/tips is welcome</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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