wrb Posted May 22, 2015 Share Posted May 22, 2015 Anyone have any suggestions? In the code below returns with error when taking delete a table record: SCRIPT: $("#add").click(function () { $.ajax({ url: '@Url.Action("AddProduto", "Produto")', type: "POST", data: $('#formprod').serializeArray(), success: function (data) { if (data.success) { $('#tabelaproduto > tbody:last').append('<tr style="font-size:10px">' + '<td hidden>' + data.id + '</td>' + '<td>' + data.descricao + '</td>' + '<td>' + '<input type="image" src="/Images/excluir.png" onclick="clicado(this)">' + '</td>' + '</tr>'); $('#formprod')[0].reset(); $("#validacaoproduto").html(""); } else { $("#validacaoproduto").html(data.msg); } } }); return false; }); function clicado(a) { console.log($(a).closest('tr')[0].rowIndex); var linhaIndex = $(a).closest('tr')[0].rowIndex; var codigo = $(a).closest('tr').children('td')[0].innerText; $.ajax({ url: '@Url.Action("DelProduto", "Produto")', type: "POST", contentType: 'application/json; charset=utf-8', data: { codigo: codigo }, success: function (data) { document.getElementById("tabelaproduto").deleteRow(linhaIndex); console.log("ok"); } }); } ERROR: <!DOCTYPE html> <html> <head> <title>Invalid JSON primitive: codigo.</title> <meta name="viewport" content="width=device-width" /> <style> body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } @media screen and (max-width: 639px) { pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; } } @media screen and (max-width: 479px) { pre { width: 280px; } } </style> </head> <body bgcolor="white"> <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1> <h2> <i>Invalid JSON primitive: codigo.</i> </h2></span> <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br><br> <b> Exception Details: </b>System.ArgumentException: Invalid JSON primitive: codigo.<br><br> <b>Source Error:</b> <br><br> <table width=100% bgcolor="#ffffcc"> <tr> <td> <code> An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code> </td> </tr> </table> <br> <b>Stack Trace:</b> <br><br> <table width=100% bgcolor="#ffffcc"> <tr> <td> <code><pre> [ArgumentException: Invalid JSON primitive: codigo.] Link to comment Share on other sites More sharing options...
Ingolme Posted May 22, 2015 Share Posted May 22, 2015 What does the server-side code look like? You're sending a GET request with a variable called "codigo" but it seems to be expecting something else. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now