jQuery POST request from inside an iFrame times out

I have an iframe that is injected into an arbitrary webpage by a bookmarklet. It points to http://localhost:5000/test, which is a simple HTML page that runs the following Javascript:

$.ajax({
  type: "POST",
  url: "http://localhost:5000/parse",
  data: {data:"hello world"}
}).done(function( msg ) {
  console.log("Success!!", arguments);
}).fail(function(jqXHR, textStatus, errorThrown) {
  console.log("Error", arguments);
});

I can see in the web inspector that the call is made, but it sits as (pending) until the request times out 30 seconds later. The server logs show that the server isn't being hit at all. The odd thing is that if I remove the data parameter in the ajax request, the server gets hit and things work as expected.

$.ajax({
  type: "POST",
  url: "http://localhost:5000/parse"
}).done(function( msg ) {
  console.log("Success!!", arguments); // this works.
});

I wouldn't expect cross-domain policy issues to be an issue since the iframe and the ajax request target are on the same domain. What am I missing here? Is there something at the browser level that is preventing this request from going through?

Answers


try adding dataType and contentType, to the ajax settings

$.ajax({
   type: "POST",
   url: "http://localhost:5000/parse",
   contentType: 'application/json; charset=utf-8',
   dataType: 'json',
   data: {data:"hello world"}
 }).done(function( msg ) {
     console.log("Success!!", arguments);
 }).fail(function(jqXHR, textStatus, errorThrown) {
     console.log("Error", arguments);
 });

Need Your Help

Counting results returned within php, efficiently

php mysql pdo count

Technologies in use: php accessing MySQL via PDO.

what does the following line of code means in xslt

xml xslt

I am learning xslt. I am trying to understand some xslt codes, but am not getting what the following line of code means:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.