PUT Ajax请求 [英] PUT Ajax request

查看:246
本文介绍了PUT Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新做的Ajax请求,并已经把下面的 Pastie 。 107线是我的$。放,并扔在萤火虫的$。把没有的功能的错误。对于Ajax请求,我知道这是不对的,但是我感到相当丢失什么,我需要做的成功的功能addCell内。我要对这个正确的方式?

编辑

 函数_ajax_request(网址,数据,回调,类型,方法){
    返回jQuery.ajax({
        键入:把',
        网址:slot_days /秀,
        数据:数据,
        成功:函数(数据)
        {
。回调($把('/ slot_days /秀',{'/ slot_days /':'slot_times'},功能(结果)

            {

            });
          )
        }
    });
}

jQuery.extend({
    放:功能(网址,数据,回调,类型){
        返回_ajax_request(网址,数据,回调,类型,'把');
}});
 

解决方案

您这里有一个错误(成功函数必须是匿名的):

 返回
    jQuery.ajax({
        键入:把',
        网址:slot_days /秀,
        数据:数据,
        成功:函数addCell(){

        }
    });
 

应该是:

 函数_ajax_request(网址,数据,回调,方法){
    返回jQuery.ajax({
        网址:网址,
        类型:方法,
        数据:数据,
        成功:回调
    });
}
 

和扩展jQuery的:

  jQuery.extend({
    放:功能(网址,数据,回调){
        返回_ajax_request(网址,数据,回调,'把');
}});
 

和示例用法的例子:

  $认沽('/ URL',{'富':'棒'},功能(结果){
    //做一些与AJAX调用的结果
});
 

I am new to doing Ajax request and have put together the following Pastie. Line 107 is my $.PUT and is throwing an error in firebug that $.PUT does not a function. As for the ajax request I know this is wrong however I am quite lost as to what I need to do inside the success function addCell. Am I going the right way about this?

Edited

function _ajax_request(url, data, callback, type, method) {
    return jQuery.ajax({
        type: 'PUT',
        url: "slot_days/show",
        data: data,
        success: function(data)
        {
callback($.put('/slot_days/show', { '/slot_days/': 'slot_times' }, function(result) 

            {

            });
          )
        }
    });
}

jQuery.extend({
    put: function(url, data, callback, type) {
        return _ajax_request(url, data, callback, type, 'PUT');
}});  

解决方案

You have an error here (the success function must be anonymous):

return 
    jQuery.ajax({
        type: 'PUT',
        url: "slot_days/show",
        data: data,
        success: function addCell() {

        }
    });

Should be:

function _ajax_request(url, data, callback, method) {
    return jQuery.ajax({
        url: url,
        type: method,
        data: data,
        success: callback
    });
}

and to extend jQuery:

jQuery.extend({
    put: function(url, data, callback) {
        return _ajax_request(url, data, callback, 'PUT');
}});  

and a sample usage example:

$.put('/url', { 'foo': 'bar' }, function(result) {
    // do something with the results of the AJAX call
});

这篇关于PUT Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆