简体   繁体   English

如何在:remote form_tag上指定“每次调用”的jQuery AJAX选项?

[英]How do I specify “per call” jQuery AJAX options on a :remote form_tag?

I have a simple form (that's enabled using ujs to make an ajax call with jQuery). 我有一个简单的表单(使用ujs启用了使用jQuery进行ajax调用的功能)。 I would like to specify the DataType of the response (by default it doesn't seem to pay much attention to "text", and I'm getting a jQuery.ajaxError. 我想指定响应的DataType(默认情况下,它似乎不太关注“文本”,而我得到的是jQuery.ajaxError。

How/where do I specify the DataType? 如何/在哪里指定数据类型? (I don't want to specify it for all calls, just a particular one.) (我不想为所有呼叫都指定它,而只为一个特定的呼叫指定它。)

dataType is declared in the ajax call. 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.')
    }
});

Or whatever your call looks like since you didn't bother to post it... >:( 还是您的电话看起来像什么,因为您不必费心将其发布...> :(

In your script, make sure you echo json_encode(); 在脚本中,确保echo json_encode(); whatever data it is you're working with. 您正在使用的任何数据。

Ugh

... form_tag ... :'data-type' => 'text' ... ... form_tag ...:'数据类型'=>'文本'...

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

I'm sure jQuery has this documented "somewhere", but I was unable to find it at this time. 我确定jQuery将此文档记录在“某处”,但目前无法找到它。 (re: jQuery and html5 data-* attributes) (关于:jQuery和html5 data- *属性)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM