Click here to Skip to main content
11,573,862 members (61,190 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Ajax REST WebService
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 0:04am
Edited 25-Feb-13 7: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

Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2015
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