Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6900531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:33:27+00:00 2026-05-27T07:33:27+00:00

Here is my View: @using (Ajax.BeginForm(Accept, FriendRequest, new { id = m.FriendRequest.Id }, new

  • 0

Here is my View:

@using (Ajax.BeginForm("Accept", "FriendRequest", new { id = m.FriendRequest.Id }, new AjaxOptions { OnSuccess = "DoSomthing" })) {
    <input type="button" value="Accept" onclick="submitAjaxform(this);" />
}

Here is the signature of the DoSomething function:

function DoSomthing(a,b,c) {
    alert(a.Status);
}

Here is my javascript function which submits the request:

function submitAjaxform(btn) {
    var form = btn.form;
    var data = $(form).serialize();
    var action = $(form).attr('action');
    var onsuccess = $(form).attr('data-ajax-success');
    $.post(action, $(form).serialize(), function (data, status, xhr) {
         var x = onsuccess + ".apply([" + data + "]);";
         eval(x);
    });
}

Here is my action method:

public JsonResult Accept(long id) {
    return Json(new {status=true,message="some message"});
}

When I run the code. The posting works well, but the onsucess of the jQuery function gives the following error in the console:

missing ] after element list

I don’t understand how to fix it. Help will be appreciated.

Edit: Thanks to Rich, here is what worked finally

function submitAjaxform(btn) {
    var form = btn.form;
    var data = $(form).serialize();
    var action = $(form).attr('action');
    var onsuccess = $(form).attr('data-ajax-success');
    $.post(action, $(form).serialize(), function (data, status, xhr) {
         window[onsuccess](data);

    });
}

Found the answer from here Calling a JavaScript function named in a variable

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:33:27+00:00Added an answer on May 27, 2026 at 7:33 am

    Your data variable is different inside the scope of the success callback, since you are not using the one declared outside I assume your code should be:

    function submitAjaxform(btn) {
      var form = btn.form;
      var data = $(form).serialize();
      var action = $(form).attr('action');
      var onsuccess = $(form).attr('data-ajax-success');
      $.post(action, $(form).serialize(), function () {
         var x = onsuccess + ".apply([" + data + "]);";
         eval(x);
      });
    }
    

    Alternatively, the data passed as the first parameter of the callback is already an object so you only need to eval your onsuccess, like so:

    function submitAjaxform(btn) {
      var form = btn.form;
      var action = $(form).attr('action');
      var onsuccess = $(form).attr('data-ajax-success');
      $.post(action, $(form).serialize(), function (data) {
         eval(onsuccess).apply([data]);
      });
    }
    

    As an aside, I would recommend not using eval wherever possible, it is expensive and allows potentially untrusted javascript to run in a browser. If it is possible to refactor your code to not require it, then you should.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in my view: <% using (Ajax.BeginForm(JsonCreate, new AjaxOptions {
This is the code in my partial view - @using (Ajax.BeginForm(SaveLayout, new AjaxOptions {
i have the following view:- <div id = partialWrapper> @using (Ajax.BeginForm(Create, Answer, new AjaxOptions
I have the following form in a partial view @model PartDetail @using (Ajax.BeginForm(Create, Part,
What I want is to pass the value of txtComments from View (using jquery/ajax)
In my html I have <h2>Title goes here</h2> @using (Html.BeginForm(Action, Controller, FormMethod.Post, new {
I using coda slider in my page. View it here: http://www.ndoherty.com/demos/coda-slider/1.1.1/ Each tab causes
I'm using ASP.NET MVC 2 and here's the issue. My View Model looks something
Here is my layout, Summary view http://img689.imageshack.us/img689/2500/yuidtsum.jpg I am using one div and many
Here's my case: I have a table view showing contacts. Add button in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.