Вопрос

I try to print

| req |
req := XMLHttpRequest new.
req open: 'GET' url: 'http://www.stackoverflow.com/' asynchronous: false.
req send: ''.
req responseText

The debugger tells me

[Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location:
"JS frame ::   http://amber-lang.net/amber/js/boot.js :: callJavaScriptMethod ::
 line 651" data: no]

This happens in a workspace on the current amber IDE on http://amber-lang.net/

Notes:

I have translated the JavaScript message

req.open("GET", url, false); 

according to the message conversion rules noted at http://amber-lang.net/documentation.html#JSObjectProxy

Update after answer by SLaks

The following code snippet

| req |
req := XMLHttpRequest new.
req open: 'GET' url: 'http://amber-lang.net/' asynchronous: false.
req send: ''.
req responseText 

works indeed when executing it in the IDE opened from http://amber-lang.net.

The answer is

'<!DOCTYPE html>
<html>
  <head>
    <title>Amber Smalltalk</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="author" content="Nicolas Petton" />

 ....
Это было полезно?

Решение

For security reasons, you cannot use AJAX to read from another domain.
(unless it explicitly allows you)

This is called the Same-origin policy.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top