Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To read an AJAX response’s HTTP status in PhantomJS, use page.onResourceReceived and inspect the callback’s response.status field. Use response.url to identify the resource you care about. The value passed to page.open’s callback is different: it reports whether the page load succeeded or failed, not the status code of an individual AJAX response.

Read the resource response, not the page-load result

PhantomJS exposes status at the resource level through onResourceReceived. That callback receives response metadata for resources loaded by the page, not just AJAX traffic. Filter on the response URL so that you can distinguish the API request from scripts, stylesheets, images, and other resources.

Here is a minimal PhantomJS script using the documented response fields:

var webpage = require('webpage');
var page = webpage.create();

page.onResourceReceived = function (response) {
  if (response.url.indexOf('/api/') !== -1) {
    console.log('URL: ' + response.url);
    console.log('HTTP status: ' + response.status + ' ' + response.statusText);
    console.log('Resource #' + response.id + ', stage: ' + response.stage);
  }
};

page.open('https://example.com', function (loadStatus) {
  console.log('Page load: ' + loadStatus); // 'success' or 'fail'
});

Replace https://example.com with the page that makes the request, and change /api/ to a path fragment that distinguishes your endpoint. The filter is illustrative; it may match more than one URL if the application uses several API routes containing that fragment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What each callback tells you

Callback or value What it represents Use it for
page.open callback value Page-load result: 'success' or 'fail'. Knowing whether PhantomJS reports that opening the page succeeded. It is not the HTTP status of a particular AJAX response.
page.onResourceReceived and response.status Response metadata for a resource, including its numeric HTTP status. Reading the status associated with a matching resource response.
page.onResourceError Information about a resource the page could not load, including its URL, ID, error code, and error description. Investigating a load failure for which response metadata is not the right diagnostic.

These answer different questions. A page can have a page-load result of 'success' while a separate resource request fails to load; conversely, an individual response’s status does not by itself tell you the overall result reported by page.open.

Match the response to the AJAX endpoint

onResourceReceived sees resource responses generally. The simplest documented way to select a response is to inspect response.url. A path-fragment check is convenient when the application has a distinctive API prefix:

page.onResourceReceived = function (response) {
  if (response.url.indexOf('/api/orders') !== -1) {
    console.log(response.status + ' ' + response.statusText + ' ' + response.url);
  }
};

For a single known endpoint, use a stricter comparison to avoid logging unrelated URLs:

var endpoint = 'https://example.com/api/orders';

page.onResourceReceived = function (response) {
  if (response.url === endpoint) {
    console.log('HTTP status: ' + response.status);
  }
};

Use the URL form that the page actually requests. If the request has a query string, the full response URL can include it, so exact equality with a URL that omits the query may not match. In that case, match the stable path or compare the URL in a way that accounts for the query string. Log the full URL while diagnosing so you can see what the callback received.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Account for repeated response callbacks

Do not assume that one resource always produces exactly one onResourceReceived call. The documented stage field includes values such as start and end; the API reference also warns that a large response delivered in multiple chunks can trigger the callback once for each chunk. Include response.id, response.stage, and response.url in diagnostic output so repeated records can be associated with the same resource and callback stage.

If your application only needs a final response record, inspect the stage and handle the final event according to the behavior of the PhantomJS runtime you are using. Do not collapse records solely because their URLs match: the same endpoint may be requested more than once, and a large response may produce multiple callback invocations. The available documentation establishes that repeated calls can occur, but does not establish every runtime’s behavior for every response or status case.

Handle resources that fail to load

A request that cannot be loaded is a different case from a response whose HTTP status you want to inspect. Register onResourceError to log PhantomJS’s resource error metadata:

page.onResourceError = function (error) {
  console.log('Resource failed: ' + error.url);
  console.log('Resource #' + error.id);
  console.log('Error: ' + error.errorCode + ' ' + error.errorString);
};

This callback reports an error code and description; it is not a substitute for response.status. Use both callbacks when you need to distinguish a received response from a resource-load failure. Avoid labeling an error code as an HTTP status code: they represent different kinds of information.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

  • You only see “success” or “fail.” That is the page-load result from page.open. Register page.onResourceReceived and read response.status for resource response status.
  • Your callback logs many unrelated URLs. The callback covers resources generally. Add a path or endpoint filter using response.url.
  • The same endpoint appears more than once. Inspect response.id and response.stage; a large response delivered in chunks may generate multiple events. Also allow for the page itself to request the same endpoint more than once.
  • No response record appears for a failed resource. Register page.onResourceError and inspect error.url, error.errorCode, and error.errorString.
  • HTTPS behaves differently from HTTP. PhantomJS troubleshooting recommends checking that SSL libraries, usually OpenSSL, are installed properly.
  • You need to interpret an unusual or non-2xx response. The API documentation defines status as the HTTP status code and gives 200 as an example, but that alone does not establish every edge case. Check the behavior in the exact PhantomJS runtime and environment you use.

Or skip the browser setup

If your goal is to capture a page rather than inspect its AJAX status, ScreenshotNeo can return a screenshot or PDF with one request. It does not replace PhantomJS resource-level status instrumentation: use the callbacks above when the HTTP status is what you need.

For a screenshot, install no browser automation in your script; send a GET request with your API key and target URL. See the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
  • Cookie banners are accepted and removed before capture, along with known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off.
  • Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Responses identify page verdict and billing status in headers.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients.
  • The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to try a screenshot request.

Frequently Asked Questions

Does `response.status` contain the response body?

No. It is the numeric HTTP status field. The response metadata described here does not provide a method for reading the AJAX response body.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can ScreenshotNeo tell me the HTTP status of an AJAX request made by the page?

The ScreenshotNeo request described here returns a screenshot or PDF; it is not a substitute for observing an individual page resource with PhantomJS callbacks.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.