带有对象数组的数据表rows.add()

时间:2016-10-21 03:11:54

标签: javascript php jquery ajax datatable

我正在尝试清除现有的Datatable并使用Ajax函数中的新数据重新绘制它。我已经用解决方案查看了其他问题来绘制数据但由于某种原因它无法正常工作。

我正在使用此功能:

$.ajax({
    url: "<?php echo site_url('exams/ajax_list'); ?>/"+site,
    type: 'GET',
    dataType: 'JSON',
    success: function(data) {
        table.clear();
        table.rows.add(data); // Add new data
        table.draw(); // Redraw the DataTable
    }
});

当我console.log(data)时,我得到一个包含7个项目的对象数组。所以我想知道为什么表没有更新?我只是在Datatable中收到一条消息,上面写着“表格中没有数据”。

1 个答案:

答案 0 :(得分:0)

我必须这样做:

=

在我的PHP文件中,我做了class RegisterViewController: UIViewController, WKNavigationDelegate , WKUIDelegate{ let url = “url” @IBOutlet weak var containerView: UIView! var webView: WKWebView? @IBOutlet weak var progressView: UIProgressView! @IBOutlet weak var backButton: UIBarButtonItem! @IBAction func barBackButtonAction(sender: AnyObject) { if self.webView!.canGoBack { self.webView!.goBack() } } @IBOutlet weak var forwardButton: UIBarButtonItem! @IBAction func barForwardButtonAction(sender: AnyObject) { if self.webView!.canGoForward{ self.webView!.goForward() } } override func viewDidAppear(animated: Bool){ super.viewDidAppear(animated) if(webView != nil) { let w = self.containerView.frame.width let h = self.containerView.frame.height webView!.frame = CGRect(x: 0, y: 0, width: w, height: h) self.containerView.addSubview(self.webView! } } override func viewDidLoad() { super.viewDidLoad() cookieMonster() self.webView = WKWebView() self.webView?.navigationDelegate = self self.webView?.UIDelegate = self self.webView!.addObserver(self, forKeyPath: "estimatedProgress", options: .New, context: nil) let req = NSURLRequest(URL: url!) self.webView!.loadRequest(req) self.webView!.allowsBackForwardNavigationGestures = true } func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) { print("WebView content loaded.") cookieMonster() progressView.setProgress(0.0, animated: false) checkToSeeIfICanGoBack() } func webView(webView: WKWebView,didStartProvisionalNavigation navigation: WKNavigation) { cookieMonster() } func cookieMonster() { let storage = NSHTTPCookieStorage.sharedHTTPCookieStorage() for cookie in storage.cookies! { storage.deleteCookie(cookie) print("Eating cookies") } NSUserDefaults.standardUserDefaults().synchronize() } override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>){ if (keyPath == "estimatedProgress") { progressView.hidden = webView!.estimatedProgress == 1 progressView.setProgress(Float(webView!.estimatedProgress), animated: true) } }

因此,添加 table.rows.add(data.data); // Add new data 让我访问数组。

console.log(data):给了我对象数组 console.log(data.data):给了我简单数组

由于