将JS返回给ajax var

时间:2016-06-20 14:29:02

标签: javascript jquery json ajax datatables

所以我正在做的是使用get resquest加载一些数据,我在httpRequest.responseText上获取此变量,我使用数据表来获得一些奇特的表,但问题是我无法在ajax:field上加载我的js var。

 <script type="text/javascript">
        var httpRequest = null;

        function SendRequest () {
            if (!httpRequest) {
                httpRequest = CreateHTTPRequestObject ();   // defined in ajax.js
            }
            if (httpRequest) {          
                    // The requested file must be in the same domain that the page is served from.
                var url = '/resources/ud_auto_executions';
                httpRequest.open ("GET", url, true);    // async
                httpRequest.onreadystatechange = OnStateChange;
                httpRequest.send (null);
            }
        }

        function OnStateChange() {
            if (httpRequest.readyState==4) {
                if (IsRequestSuccessful (httpRequest)) {    // defined in ajax.js
                alert ("hello im coming");

                }
                else {
                    alert ("Operation failed.");
                }
            }
       }
</script>

我在ajax上遇到麻烦:

  <script>
        $(document).ready(function() {
        $('#example').DataTable( {
            "AutoWidth": true,
            "ajax": httpRequest.responseText

1 个答案:

答案 0 :(得分:0)

你过度复杂化了。尝试:https://datatables.net/examples/index