Resend aoData.push parameters with fnReloadAjax?

Resend aoData.push parameters with fnReloadAjax?

anaganag Posts: 48Questions: 2Answers: 7
edited September 2013 in General
When a page on my site loads an AJAX call is made to WordPress admin ajax, an action is passed in aoData.push telling WordPress what action to fire, the action simply creates the json response to build the table

[code]
"sAjaxSource":'http://example/wp-admin/admin-ajax.php',
"fnServerParams": function ( aoData ) {
aoData.push({ "name": "websiteid", "value":'<?php echo $pageID; ?>' },{"name":"action","value":'set_alert_dt'} );
}
[/code]

This works fine for when the page loads. Now I also have a front end form which creates posts and within the AJAX success I have oTableAlert.fnReloadAjax();

This fails because it requests the sAjaxSource URL but does not send aoData.push.

My work around was to place this code in the AJAX success

[code]
var sNewSource = "<?php echo admin_url('admin-ajax.php'); ?>?action=set_alert_dt";
alert(sNewSource);
oTableAlert.fnReloadAjax(sNewSource);
[/code]

I'm technically hard coding in the parameters to be sent along with the new AJAX request.

Is there a way to resubmit the aoData.psh with fnReloadAjax ?

Thanks

Replies

  • anaganag Posts: 48Questions: 2Answers: 7
    I've changed my code and it's working but is this the correct syntax?

    [code]
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
    aoData.push({ "name": "websiteid", "value":'<?php echo $pageID; ?>' },{"name":"action","value":'set_alert_dt'} );
    oSettings.jqXHR = $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success":function(json) {
    results = json;
    console.log(results);
    alert("New success message");
    fnCallback(results);
    }
    } );
    }
    [/code]
This discussion has been closed.