2009-07-22 6 views
1

Je suit l'appel ajax:

var empId = $(this).attr('name').replace(/disp/,''); 
    $.ajax({ 
     url: '<%= Url.Action("AjaxDisp") %>', 
     data: { id: empId, format: 'json' }, 
     dataType: 'json', 
     success: function(data,status) { 
     // populate the popup and display it    
     } 
    }); 

EMPID est là (je l'utilise alert (EMPID), pour le tester, il le bien). Mais dans la méthode d'action AjaxDisp (int id, format strng), je peux obtenir l'identifiant, mais je peux obtenir format = "json".

Pourquoi?

+0

Pouvez-vous afficher l'en-tête du message comme contenu affiché dans firebug? –

Répondre

1

Convertit l'objet (transmis aux données) en chaîne JSON.

var empId = $(this).attr('name').replace(/disp/,''); 
    $.ajax({ 
     url: '<%= Url.Action("AjaxDisp") %>', 
     data: JSON.stringify({ id: empId, format: 'json' }), //converting your object to JSON string. 
     dataType: 'json', 
     success: function(data,status) { 
     // populate the popup and display it    
     } 
    }); 
+0

Merci. Quand l'essayer et l'exécuter. Il a dit que JSON n'est pas défini. – KentZhou

+0

Vous devrez inclure cette bibliothèque JSON http://www.json.org/json2.js – SolutionYogi

+1

L'analyseur JSON natif est disponible dans Internet Explorer 8 et FireFox 3.1+ Pour les autres navigateurs, vous aurez besoin de la bibliothèque JSON. –