Solved

jquery post data

Posted on 2014-01-23
5
246 Views
Last Modified: 2014-01-23
Ok a little new to Jquery, trying to post data to my controller but getting 500 error because I can not post any data.

$(document).ready(function () {
         $("a").click(function () {
             if ($(this).val && $(this).attr("id")) {
                 //alert(this.id);
                 $.ajax({
                     url: this.action,
                     type: this.method,
                     data: $(this).serialize(),
                     success: function (result) {
                         $.post('@Url.Action("mylist", "List")', function (id) {
                             alert(this.id);
                                //$.each(data, function (index, value) {
                                //    $("a").val(this.id)
                                //    alert(this.id);
                                //});
                            });
                        }
                   });
             }
             else {
                 'nothing happen'
             }
           
         });
     });
 <a href="#" id="33" class="ui-link-inherit" >link1</a>

Open in new window

0
Comment
Question by:sevensnake77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39803660
Where is the error happening?
An anchor tag does not have an action or method attribute.
url: this.action,
type: this.method
data: $(this).serialize(),
,

If you want the FORM attributes then use

url: $(this).closest("form").attr("action"),
type: $(this).closest("form").attr("method"),
data: $(this).closest("form").serialize(),
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 39803684
Well nothing is getting past at all.
but if i put a alert before
if ($(this).val && $(this).attr("id")) {
               alert(this.id);

Open in new window

i get the value but I am problem posting after the $.ajax
0
 
LVL 58

Expert Comment

by:Gary
ID: 39803691
The first thing to do is in my first comment, your code is trying to get attributes that don't exist.
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 39803865
got it thanks
0
 
LVL 58

Expert Comment

by:Gary
ID: 39803894
Why only a grade B?
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question