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

  • Home
  • SEARCH
  • 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 8116659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:54:01+00:00 2026-06-06T03:54:01+00:00

I am trying to write a controller method and a corresponding view which will

  • 0

I am trying to write a controller method and a corresponding view which will call the controller on web2py using Ajax. The idea is to make a small update on the database and return a simple updated message on a target div using Ajax. Below is contoller method:

def deleteajax():
recid1 = request.vars.recid
reptype1 = request.vars.reptype
if recid1 == None:
    out = 'Missing Param : recid'
    return out
if reptype1 == None:
    reptype1 = 'pr'        
if reptype1 == 'pr':
    row = db2(db2.prs_mailed.id==recid1).select().first()
    return str(row.id)
elif reptype1 == 'tb':
    row = db2(db2.tbs_mailed.id==recid1).select().first()
else:
    return 'Please provide the parameter : rep'
if row['action'] == 'D':
    out = 'Already deleted'
    return out
else:
    row.update_record(action='D')
    out = 'Deleted Successfully!'
    return out

and this is how I am calling the same from view:

     <form>{{
     response.write('<input type="hidden" name="recid" value="'+str(response._vars['prs']['id'][k])+'"/>',escape=False)}}
     <input type ='button' name="del" value = "D"  onclick="ajax('deleteajax', ['reid'], 'target')" />
     <div id="target"></div>
     </form>

I have tested the controller individually using a POST call and that works. Even the AJAX call works and displays error messages like ‘Missing Param : recid’ on the target div. I even tried modifying the controller to show more messages after finishing each statement. However, post any database operation, no commands from the controller are getting executed, nor is anything showed on the target div. Where am I going wrong?

  • 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-06-06T03:54:03+00:00Added an answer on June 6, 2026 at 3:54 am

    First, instead of this:

    {{response.write('<input type="hidden" name="recid" value="' +
        str(response._vars['prs']['id'][k])+'"/>',escape=False)}}
    

    Just do this:

    <input type="hidden" name="recid" value="{{=prs['id'][k])}}"/>
    

    There’s no need to use response.write or to access the “prs” object through response._vars (all the items in response._vars are available globally in the view environment).

    Regarding the Ajax problem, your input element name is “recid”, but your ajax() call refers to “reid”. Change the latter to “recid” and see if it works.

    UPDATE:

    To create multiple unique recid’s, you could do:

    name="{{='recid%s' % prs['id'][k]}}"
    

    Then, in the controller, check for request.vars that start with “recid”:

    recid = [v for v in request.post_vars if v.startswith('recid')]
    if recid:
        recid = int(recid[0][5:])
        [code to delete record with id==recid]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to write a delegate to a view controller which has
I'm trying to write code in my controller that when run, will create a
I'm trying to write a unit test for a controller using Zend and PHPUnit
I'm trying to write a controller method that returns an ActionResult. In this method,
I have two views which will both use the same Controller method: //webServiceController.cs //The
I'm trying to write a method that will operate like this: NSString *responseData =
I'm trying to write this method in my controller: @ResponseBody @RequestMapping(value = {/getTeams}, method
I am trying to write a unit test for an action method which calls
I am trying to write a method in my application controller that would be
I am trying to write my delete method in my comment controller. My comment

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.