Solved

jquery post data

Posted on 2014-01-23
5
244 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

685 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