1

I need to post result with Ajax, but the API I'm posting to uses 302 redirect to display results. Ajax won't follow the redirect, so I can never get my data. I just get a null response.

I can do a casper.open() and then it will at least post and follow to get results, but I don't want to navigate off page to get this result.

Any suggestions?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222

1 Answers1

1

According to the question Why browser do not follow redirects using XMLHTTPRequest and CORS? this may be related to the problem with a cross-domain request and preflight checks.

The solution would be to run CasperJS with the --web-security=false option which PhantomJS provides:

casperjs --web-security=false script.js

Another possibility is to open a new tab/window. A casper instance manages only one main page (and multiple popups or child windows). If you're not in the test environment of CasperJS, then you can create a second casper instance and navigate to the other page. My answer here provides a drop-in solution for this with a usage example.

Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • I have tried with web-security=false set but still getting null. It works perfectly in PH 1.98 but 2.0 is where it seems to have issues. Not sure if its a bug or what. – David James Schlaegel Aug 14 '15 at 01:20