Topic: Update values through AJAX

Hi all

I am using ajax to update the values, here in Jquery ajax method I am specifying TYPE:"PUT" and URL:"controller/:id.json" to update but it is routing to GET show and not updating .

Really I got stuck here and not able figure out whats the problem. Please help me..

Here I am putting the code snippet

function update_pfrate(id)
{
    var value1=$('#value1').val();
    var value2= $('#value2').val();
   
    var datastring="controller[value1]="+value1+"&controller[value2]="+value2

    $.ajax({
    type:"PUT",
    beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
    url:"/controller/"+id+".json",
    data:datastring,
    dataType: "json",
    success:function(result){

        $('#result_response').html("Updated.");
    },
    error: function(data) { // 500 Status Header
        error_data(data,'#result_response');
    }
    });
}

Last edited by vinaykp3 (2012-07-30 07:21:41)

Re: Update values through AJAX

Javascript is programming language executed by your browser, Ajax is programming technique you can use to fetch data from server without reloading the whole page (explanation http://www.w3schools.com/ajax/ajax_example.asp). If you're confused about javascript and ajax related things go through some tutorials and digg into, before using.