using sAjaxSource with "bServerSide": true

using sAjaxSource with "bServerSide": true

qwert_ukgqwert_ukg Posts: 9Questions: 0Answers: 0
edited September 2011 in General
why it works:
[code]
oTable = $('#price').dataTable({
"bProcessing": true,
//"bServerSide": true,
"sAjaxSource": "http://zamanpharm.kz/dub/templates/bt_okto/reload_price2.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": function (code){
fnCallback(code);

$.getJSON("http://zamanpharm.kz/dub/templates/bt_okto/names_price.php", function(data){
var i=0;
$("#price tbody tr").each(function(){
$(this).attr("name", data.id[i]);
i++;
});
});

summPlus();
summMinus();
summInput();
strDel();
}
} );
},
"sScrollY": $(window).height()-102,
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
[/code]
as well - there is no:
[code]
oTable = $('#price').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://zamanpharm.kz/dub/templates/bt_okto/reload_price2.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": function (code){
fnCallback(code);

$.getJSON("http://zamanpharm.kz/dub/templates/bt_okto/names_price.php", function(data){
var i=0;
$("#price tbody tr").each(function(){
$(this).attr("name", data.id[i]);
i++;
});
});

summPlus();
summMinus();
summInput();
strDel();
}
} );
},
"sScrollY": $(window).height()-102,
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
[/code]

Replies

  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited September 2011
    Hm, just discovered that the reason your sources are all wonky looking above is that the forum is converting text starting with 'http' into anchor links, even inside the code block. ;-)

    One of my suggestions still holds: you don't need to (although you can) fully qualify the whole URL. Assuming you're in the same directory,

    [code]
    "sAjaxSource": "reload_price2.php",
    [/code]

    is a better way of stating your source.

    I'm not sure I understand how to solve the problem, assuming what you're saying is that sAjaxSource does not work when bServerSide is true. Personally I would just forget about sAjaxSource and put my URL into the "url" parameter of my .ajax function (inside fnServerData).
  • qwert_ukgqwert_ukg Posts: 9Questions: 0Answers: 0
    [quote]GregP said: put my URL into the "url" parameter of my .ajax function (inside fnServerData). [/quote]
    how to do this?
    p.s.
    syntax highlighter do this: http://zamanpharm.kz/dub/templates/bt_okto/reload_price2.php"

    just http://zamanpharm.kz/dub/templates/bt_okto/reload_price2.php
  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited September 2011
    I feel like I might be going crazy since the example code uses sAjaxSource just fine, but I can't see why this wouldn't work also:

    [code]
    ...
    "bProcessing": true,
    "bServerSide": true,
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": "reload_price2.php",
    "data": aoData,
    "success": function (code){
    fnCallback(code);

    $.getJSON ...
    [/code]

    the fnServerData function is passed sSource (whatever that might be at this point; it SHOULD have been your sAjaxSource, but you say it doesn't work), but then we just never use it. Instead we directly place the URL into the URL parameter of the $.ajax() call.
  • qwert_ukgqwert_ukg Posts: 9Questions: 0Answers: 0
    where in this code "sAjaxSource"?
    without "sAjaxSource" doesn't work!!!(((((
  • qwert_ukgqwert_ukg Posts: 9Questions: 0Answers: 0
    как мне вешать события на строки после очередной подгрузки из аякса????? блядь!!!!!
  • qwert_ukgqwert_ukg Posts: 9Questions: 0Answers: 0
    edited September 2011
    how i can set events on row (such as click etc), after the next upload of Ajax ????? damn !!!!!
    becouse i click on "next page button" - Ajax upload - my old events has disappeared(((((((((
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    either set them in fnDrawCallback (or fnRowCallback) or use .live() event binding
  • qwert_ukgqwert_ukg Posts: 9Questions: 0Answers: 0
    [quote]fbas said: either set them in fnDrawCallback (or fnRowCallback) or use .live() event binding [/quote]

    why fnDrawCallback runs 2 times???

    [code]function priceReload(){

    oTable2.fnDestroy();
    oTable2 = $('#zakaz').dataTable({
    "sAjaxSource": 'http://zamanpharm.kz/dub/templates/bt_okto/reload_base.php',
    "sScrollY": $("#rec_inner").height() - 65,
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "bPaginate": false,
    "bFilter": false,
    "bInfo": false,
    "aoColumns": [
    { "sWidth": "40px" },
    { "sWidth": "500px" },
    { "sWidth": "60px" },
    { "sWidth": "145px" },
    { "sWidth": "65px" }
    ],
    "fnDrawCallback": function() {

    $.getJSON("http://zamanpharm.kz/dub/templates/bt_okto/names.php", function(data){
    var i=0;
    $("#zakaz tbody tr").each(function(){
    $(this).children().next().next().next().addClass("edit");
    $(this).attr("name", data.id[i]);
    i++;
    });
    });
    summPlus();
    summMinus();
    summInput();
    strDel();
    }
    });
    $('#search').focus().select();
    }[/code]
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    It gets called when the Ajax request goes out initially (because DataTables has done a draw to show the 'loading...' message) and then a draw when the data is loaded - hence two calls to fnDrawCallback. Might you actually want to use fnInitComplete for your Ajax call?

    Allan
  • qwert_ukgqwert_ukg Posts: 9Questions: 0Answers: 0
    why how i use "fnServerData" and has adding to "aoData" {"name": "username", "value": xxx}
    replay from server, waiting a have long time, downloading not all (total 5000) and is empty
    however param "username" has uploading on server

    please help!

    [code]oTable = $('#price').dataTable({

    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "reload_price2.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    aoData.push({ "name": "username", "value": xxx});
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    } );
    },
    ...[/code]

    sorry for spelling, i'm from Russia
  • GregPGregP Posts: 500Questions: 10Answers: 0
    I don't think I see anything actually wrong with this. If the above were my code, I would probably switch gears and look at the reload_price2.php script.

    When you say "not all (total 5000)", are you actually expecting 5000 to be returned? That would not be the typical way of using server-side processing. Normally we use server-side because we want to send back a reduced data set (based on filtering and pagination).
  • qwert_ukgqwert_ukg Posts: 9Questions: 0Answers: 0
    edited September 2011
    [quote]GregP said: are you actually expecting 5000 to be returned?[/quote]
    no!!! i use server-side processing!
    without "fnServerData" all works great.
    but if data returned from server mach smaller (50 ), all downloading with "fnServerData" ))
    what the reason of this?
    thru 8 hours show reload_price2.php
  • GregPGregP Posts: 500Questions: 10Answers: 0
    If you don't use fnServerData, the method for retrieving the data is GET. In your sample code, you have specified type as "POST". Try switching "type" parameter to "GET".
  • qwert_ukgqwert_ukg Posts: 9Questions: 0Answers: 0
    edited September 2011
    Thanks! it work
This discussion has been closed.