Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jquery post data

Posted on 2014-01-23
5
Medium Priority
?
248 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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 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