JavaScriptからRailsコントローラーにjsonオブジェクトを送信しようとしていますが、このエラーが発生し続けます
MultiJson::DecodeError (lexical error: invalid string in json text.
tag=hello
(right here) ------^
私はyajl、rails 3.1、jquery1.6を使用しています。
gemfilegemでのYajlのセットアップ 'yajl-ruby'
config / application.rb
require 'yajl/json_gem'
私のコード
ajax関数
var myobj={"tag":"hello"};
$.ajax({
url: 'ips/create',
type: 'post',
contentType: 'application/json; charset=UTF-8',
accept: 'application/json',
dataType: 'json',
data:$.param(myobj),
success: function(res) {
if (res.ImportResponse !== void 0) {
console.log('Success: ' + res);
} else if (res.Fault !== void 0) {
console.log('Fault: ' + res);
}
},
error: function() {
console.error('error!!!!');
}
});
*In controller*
parser = Yajl::Parser.new
hash = parser.parse(request.body.read)