?
Solved

jquery post data

Posted on 2014-01-23
5
Medium Priority
?
247 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:Seven price
[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 1500 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:Seven price
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:Seven price
ID: 39803865
got it thanks
0
 
LVL 58

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

777 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