0

我有一个简单的表单(使用 ujs 启用以使用 jQuery 进行 ajax 调用)。我想指定响应的 DataType(默认情况下它似乎不太关注“文本”,我得到一个 jQuery.ajaxError。

如何/在哪里指定 DataType?(我不想为所有调用指定它,只是一个特定的调用。)

4

2 回答 2

0

dataType 在 ajax 调用中声明。

$.ajax({
    url: 'myurl.com/script.php',
    type: 'GET',
    dataType: 'json',
    data: 'a=1&b=2',
    success: function(){
        alert('Great Success!')
    },
    error: function(){
        alert('Bummer.')
    }
});

或者你的电话看起来像什么,因为你没有费心发布它......> :(

在您的脚本中,确保您echo json_encode();使用的是任何数据。

于 2013-04-29T15:50:10.207 回答
0

... form_tag ... :'data-type' => 'text' ...

http://www.w3.org/TR/2011/WD-html5-20110525/elements.html#embedding-custom-non-visible-data-with-the-data-attributes

我确信 jQuery 有这个记录在“某处”,但我此时无法找到它。(re: jQuery 和 html5 data-* 属性)

于 2013-04-29T16:36:24.193 回答