- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在跟踪this tutorial,以便从dart到Rails后端应用程序上的ruby运行POST方法。因此,我第一次尝试了本教程所示的代码,只是更改了URL和JSON数据。
void main() {
String jsonData = '{"color":"blue","x":"100","y":"100"}';
saveData(jsonData, onSuccess); // send the data to // the server
}
void onSuccess(HttpRequest req) {
print(req.responseText); // print the received raw JSON text
}
void saveData(String data, onSuccess(HttpRequest req)) {
HttpRequest req = new HttpRequest(); // create a new XHR
// add an event handler that is called when the request finishes
req.on.readyStateChange.add((Event e) {
if (req.readyState == HttpRequest.DONE &&
(req.status == 200 || req.status == 0)) {
onSuccess(req); // called when the POST successfully completes
}
});
var url = "http://localhost:3030/colored_rectangles.json";
req.open("POST", url); // Use POST http method to send data in the next call
req.send(data); // kick off the request to the server
}
# POST /colored_rectangles
# POST /colored_rectangles.json
def create
@colored_rectangle = ColoredRectangle.new(params[:colored_rectangle])
respond_to do |format|
if @colored_rectangle.save
format.html { redirect_to @colored_rectangle, notice: 'Colored rectangle was successfully created.' }
format.json { render json: @colored_rectangle, status: :created, location: @colored_rectangle }
else
format.html { render action: "new" }
format.json { render json: @colored_rectangle.errors, status: :unprocessable_entity }
end
end
end
class ColoredRectangle < ActiveRecord::Base
attr_accessible :color, :x, :y
end
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
http://localhost:3030/colored_rectangles.json
REXML::ParseException (The document "{\"color\":\"blue\",\"x\":\"100\",\"y\":\"100\"}" does not have a valid root):
activesupport (3.2.9) lib/active_support/xml_mini/rexml.rb:35:in `parse'
C:in `parse'
etc....
req.overrideMimeType("application/json");
void saveLanguageData(String data, onSuccess(HttpRequest req)) {
HttpRequest req = new HttpRequest(); // create a new XHR
// add an event handler that is called when the request finishes
req.on.readyStateChange.add((Event e) {
if (req.readyState == HttpRequest.DONE &&
(req.status == 200 || req.status == 0)) {
onSuccess(req); // called when the POST successfully completes
}
});
var url = "http://localhost:3030/colored_rectangles.json";
req.setRequestHeader("Content-type", "application/json"); //This was added
req.open("POST", url); // Use POST http method to send data in the next call
req.send(data); // kick off the request to the server
}
Exception: Error: INVALID_STATE_ERR: DOM Exception 11
Stack Trace: #0 HttpRequest.setRequestHeader (E:\b\build\slave\dartium-win-full-trunk\build\src\build\Release\obj\global_intermediate\webkit\bindings\dart\dart\html\HttpRequest.dart:34:1)
#1 saveLanguageData (http://localhost:3030/rademo_dart/web/rademo.dart:45:23)
#2 main (http://localhost:3030/rademo_dart/web/rademo.dart:10:19)
最佳答案
哦,好了,我找到了解决问题的答案...实际上,需要在req.open之后调用setRequestHeader,因此saveData方法代码如下:
void saveData(String data, onSuccess(HttpRequest req)) {
HttpRequest req = new HttpRequest(); // create a new XHR
// add an event handler that is called when the request finishes
req.on.readyStateChange.add((Event e) {
if (req.readyState == HttpRequest.DONE &&
(req.status == 200 || req.status == 0)) {
onSuccess(req); // called when the POST successfully completes
}
});
var url = "http://localhost:3030/colored_rectangles.json";
req.open("POST", url); // Use POST http method to send data in the next call
req.setRequestHeader("Content-type", "application/json");
req.send(data); // kick off the request to the server
}
关于ruby-on-rails - HttpRequest.setRequestHeader在Dart上生成DOM异常11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13804294/
我使用 ajax 将文本发送到我的服务器。如果我删除下面的行,它就会中断。 xhr = new window.XMLHttpRequest(); xhr.open("POST", config.url
我正在尝试向 unsplash.com 发出异步 XMLHttpRequest 来抓取图片。我创建了一个开发帐户,并获得了以下信息: 授权码 应用程序 ID secret 我将授权代码放入 setRe
普通的 Jquery ajax 请求抛出此错误: 语法错误:无法执行“setRequestHeader”... }↵}' 不是有效的 HTTP header 字段值。 $.ajax({url: '/a
这是我的代码 // assume var data has japanese characters xmlhttp.open("POST","adminUpdate?&value="+data,tru
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: Overcoming Cross-Domain issues 是否可以跨域 $.ajax setRequestHea
我正在使用 xhr.setRequestHeader 在 jQuery 中使用 beforeSend 设置身份验证。代码是这样的: beforeSend: function (xhr) { x
我正在尝试使用 AJAX 来调用 SOAP 调用(不是跨站点的,所以它不应该遇到代理等问题) 但是,这需要 XHR 中的两个自定义 header ,即 SOAPTarget 和 SOAPAction。
这个 java 语句在 python 中相当于什么? post.setRequestHeader("Cookie", jSessionID); 我很困惑这到底是一个 cookie 还是只是用“Cook
我正在尝试向 ajax 请求添加 header 。 我使用 setRequestHeader 但它什么也没做。我可以在 firefox 中查看请求 header 不包含身份验证!我做错了什么? 以及如
如果您不知道答案,请竖起大拇指。 function local_upload_photo(form_data) { var boundary = "----------------
我正在尝试从 javascript 发送带有授权 header 的 http POST,并发现许多推荐此配置的答案 var device_address = 10.25.148.164; var de
我正在尝试使用以下代码连接到 Web 数据库,但在 VBA 中自动化时它似乎不起作用。登录名和密码很好,因为我可以手动连接它们。 对象:“WinHttp.WinHttpRequest.5.1”是否可能
我想在我的 xhr 中添加 header 。 当我使用 setRequestHeader 时,它实际上所做的是向 Access-Control-Request-Headers 添加一个值。 如果我编码
IE 9 开发人员工具显示“未指定错误”。在这行代码中: xmlhttp.setRequestHeader ("If-Modified-Since", "Sat 1 Jan 2005 00:00:00
以下 JS 函数应向 发送 GET 请求 http://127.0.0.1:5000/api.xml 与 ?query=toast function sendRequest(str){ var
我尝试发出跨域请求。为了能够做到这一点,我必须设置一个 http header 。 $.ajax({ type: 'GET', url:
我必须为我的 ajax 调用 (POST) 设置自定义请求 header 。由于我使用客户端/服务器框架( ZK ),因此我无法掌握整个过程(从 open() 到 send())。这就是为什么我只能按
我正在编写一个位于系统中的 JS 脚本,该脚本现在通过 jqXHR.setRequestHeader() 在使用 jQuery.ajaxPrefilter() 注册的函数中向所有 Ajax 请求添加自
在 hello world cordova 2.3.0 应用程序中尝试使用 ripple 添加了基本的 BackboneJS 代码,我得到上面显示的错误 我已经
我的 VBA 代码发送除 Cookie 信息之外的所有 header 。 Dim oXMLHttpRequest As Object Set oXMLHttpRequest = CreateObjec
我是一名优秀的程序员,十分优秀!