Solved

jquery post data

Posted on 2014-01-23
5
240 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
  • 3
  • 2
5 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
got it thanks
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Why only a grade B?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to dynamically set the form action using jQuery.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now