2012-06-24 19 views
1

ajax jsfiddle不適用於最新的jQuery(1.7.2),但1.4.x可以。使用螢火蟲我可以看到反應是正確的,但成功並沒有被解僱。如何在jsfiddle中使用最新的jQuery工作ajax?

任何想法如何使它適用於最新的?

function ajaxcall() { 
    $.ajax({ 
     type: 'post', 
     url: '/echo/html/', 
     dataType: 'html', 
     data: { 
      // 'html': button + script, 
      'html': "test", 
     }, 
     success: function(data) { 
      //alert("ajax finished"); 
      $('#table').html(data); 
     }, 
     dataType: 'text/html' 
    }); 
} 

最終工作的版本是here

+3

使用的dataType爲數據類型: 'HTML',將工作,在您r你已經聲明dataType twic – Dhiraj

+0

更新我的答案與工作小提琴。我完全消除了'dataType',所以......?此外,抵達時還有五秒鐘的延誤。 –

+0

@Dhiraj:你能否從你的評論中創建一個答案,以便我可以接受它? – Radek

回答

2

使用dataType: 'html'應該這樣做

function ajaxcall() { 
    $.ajax({ 
     type: 'post', 
     url: '/echo/html/', 
     dataType: 'html', 
     data: { 
      // 'html': button + script, 
      'html': "test", 
     }, 
     success: function(data) { 
      //alert("ajax finished"); 
      $('#table').html(data); 
     }, 
    }); 
} 

DEMO

希望這有助於

+0

我以爲你會說我有我使用過的數據類型兩次;-) – Radek

2

編輯:

下面是使用/echo/html/和jQuery $.ajax()工作版本。

$(document).ready(function(){ 
    var $button = $('#createissue'); 

    var test = function(){ 
     $.ajax({ 
      url: '/echo/html/', 
      type: 'post', 
      success: show, 
      data: { 
       delay: 5, 
       html: '<table><tr>' + 
        '<th>summary</th><td>This is a summary for an issue</th>'+ 
        '<th>reporter</th><td>Christopher Robin</th>'+ 
        '<th>assignee</th><td>Jared from Subway</th>'+ 
        '<th>securitylevel</th><td>Hands in the air! Everyone is suspect.</th>'+ 
        '<th>description</th><td>Something descriptive goes here, I suppose.</th>'+ 
        '</tr></table>' 
      } 
     }); 
    }; 

    var show = function(table) { 
     console.log(table);  
     $(document.body).append(table); 
    }; 

    $button.click(test); 
}); 

http://jsfiddle.net/userdude/YCecC/1/


我知道我有一個地方,但不幸的是我沒有一個純HTML版本準備就緒。

var test = function(){ 
    $.ajax({ 
     url: '/echo/json/', 
     success: show, 
     type: 'post', 
     data: { 
      delay: 5, 
      json: JSON.stringify({ 
       summary: 'This is a summary for an issue', 
       reporter: 'Christopher Robin', 
       assignee: 'Jared from Subway', 
       securitylevel: 'Hands in the air! Everyone is suspect.', 
       description: 'Something descriptive goes here, I suppose.' 
      }) 
     } 
    }); 
}; 

var show = function(json) { 
    var $row, 
     $cell, 
     rows = {}; 

    $tbody.empty(); 

    for (field in json) { 
     $row = $tr.clone(); 

     $cell = $td.clone(); 
     $cell.text(field); 

     $row.append($cell); 

     $cell = $td.clone(); 
     $cell.text(json[field]); 

     $row.append($cell); 

     rows[field] = $row; 
    } 

    $tbody.append(
     rows.summary, 
     rows.securitylevel, 
     rows.reporter, 
     rows.assignee, 
     rows.description 
    ); 

    $table.append($tbody); 

    $(document.body).append($table); 
}; 

http://jsfiddle.net/userdude/YCecC/

相關問題