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 726379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:26:42+00:00 2026-05-14T06:26:42+00:00

$.ajax({ type: POST, url: WebService.asmx/AddVisitor, data: {‘fname’:’dave’, ‘lname’:’ward’}, contentType: application/json; charset=utf-8, dataType: json });

  • 0
$.ajax({ 
  type: "POST", 
  url: "WebService.asmx/AddVisitor",
  data: "{'fname':'dave', 'lname':'ward'}", 
  contentType: "application/json; charset=utf-8", 
  dataType: "json"
});

I have an Asp.Net WebMethod that takes a firstName, lastName…..as a parameter, how do I send that stuff to that method using the JQuery Ajax method. if i hardcode the above it works without any problem

but if i pass dynamic it fails

var firstName = $("[id$='txtFirstName']");
var lastName = $("[id$='txtLastName']");

//data: "{'firstName':'Chris','lastName':'Brandsma'}"<br>

data: "{'firstname':'" + escape(firstName.val()) + "','lastName':'" + escape(lastName.val()) + "'}",

my WebMethod looks like this

[WebService(Namespace = “http://tempuri.org/“)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class VisitorWS : System.Web.Services.WebService {
[WebMethod]
public bool AddVisitor(string firstName, string lastName)
{
return true;
}

what wrong here? i have tried with eval and escape none of that works.

Thanks for any help.

  • 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-14T06:26:43+00:00Added an answer on May 14, 2026 at 6:26 am

    i have figured out and here it works without adding scriptmethod to it.

    var myData = { 
      "firstName": escape($('#txtFirstName').val()),
      "lastName": escape($('#txtLastName').val())
    };
    
    $.ajax({
      // ...  
      data: JSON.stringify(myData),
      // ...
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(document).ready(function() { $.ajax({ type: 'post', async: false, url: 'WebService.asmx/GetCustomerInformation', data: '{}', contentType: 'application/json;charset=ytf-8', dataType:
am calling a webservice from my jquery as $.ajax({ type: POST, url: /DataService.asmx/Search, contentType:
.ajax({ type: 'POST', url: '..serverices/ajaxserver.asmx', data: 'lname='+ $('#lastname').val() }); return false; if #lastname has
$.ajax({ type: POST, url: /zzz/bbb/abcd.aspx?deleteIDs= + request_ids, contentType: application/x-www-form-urlencoded, data: '', dataType: html, complete:
$.ajax({ type: POST, url:'/saveLayout', data: {id : layoutId, section : arrSection}, success: function(response){ $('#successMsg').addClass(errorBox);
The code I want to work: $.ajax({ type: POST, url: _Source/ajap/ajap.nlSrch.php, data: { sndJson
$(#button_title_delete).click(function(){ jQuery.ajax({type:'POST', url:'delete.php', data: 'id='+$(bid).val(), success: function(veri) { $(#delete_result).html(veri);} }); }); When i click
I have a form which POST's its data via AJAX: $.ajax({ type: POST, url:
Im doing a simple ajax request like:` $.ajax({ type: 'POST', url: 'http://' + serverIP
When I post my ajax data to my webservice I keep getting this error.

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.