[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

creating generic ajax method

Posted on 2014-03-26
1
Medium Priority
?
409 Views
Last Modified: 2014-03-26
hi all,

I am trying to create a generic AJAX method for calling on a site

function runAjax(webmethod, fieldname, fieldtext) {
    
    return $.ajax({
        type: "POST",
        url: webmethod,
        data: JSON.stringify({ username: fieldtext }),
        contentType: "application/json; charset=utf-8",
        dataType: "json"
    });
}

Open in new window


the above code works fine, however when I substitute username to fieldname (i.e. to the passed variable, the method doesnt fire?

Is there anyway I can inject the fieldname text into this method?

thanks.
0
Comment
Question by:flynny
[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
1 Comment
 
LVL 5

Accepted Solution

by:
jayakrishnabh earned 2000 total points
ID: 39956119
function runAjax(webmethod, fieldname, fieldtext) {
    var jsonObject= {};
            jsonObject[fieldname] = fieldtext;

    return $.ajax({
        type: "POST",
        url: webmethod,
        data: jsonObject,
        contentType: "application/json; charset=utf-8",
        dataType: "json"
    });
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

650 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