Click here to Skip to main content
13,352,631 members (39,393 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi everyone

I am trying to call the Rest services using Ajax Call with Method = Post; My Ajax code is below. In my alert i am getting my results added. But in the Html form i was not able to add this using AJAX.
                    type: "POST", //GET or POST or PUT or DELETE verb
                    url: "http://localhost:8080/karthick", // Location of the service
                    contentType: "application/json", // content type sent to server
                    dataType: "json", //Expected data format from server
                    processdata: true, //True or False
                    success: function (json)
                    var result = json.firstName;
                    error: ServiceFailed

                return false;


function ServiceFailed(xhr) {
            if (xhr.responseText) {
                var err = xhr.responseText;
                if (err)
                    error({ Message: "Unknown server error." })


                               <table id="karthi">

                                       <td align="left"><input type="text" id="name" class="medium" name="" value=""></td>


                                       <td align="left"><input type="text" id="firstname" class="medium" name="" value=""></td>


                                       <td colspan="2"><button id="btnAjax" onClick="submit" type="button">Submit</button> or <a href="#">Cancel</a></td>




I want to add the name & firstname parameter in the HTML form using the ajax call with the web-service. Kindly assist me on this.

Posted 25-Feb-13 1:04am
Updated 25-Feb-13 8:32am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try like this
function GetSearchResult() {
    $.support.cors = true;
    var searchUrl = URL;
    var params = { "ID": Id,
        "Name": name
        cache: false,
        type: "POST",
        async: true,
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        url: searchUrl,
        data: JSON.stringify(params),
        success: function (data) {
        error: function (xhr) {

Hope this helps

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100