0

Ok, Im fairly new making Ajax calls and I wanted to know if it is possible to send more than 1 parameter in an Ajax call.

in my $.Ajax im sending an object and a string.

 $.ajax({
            type: 'POST',
            url: urlAction,
            cache: false,
            data: JSON.stringify(customer,telephone),
            contentType: "application/json; charset=utf-8",
            success: function (data) {
            //Do something
            },
            error: function (xhr, ajaxOptions, thrownError) {
            //Do something
            }
        });

Is it possible to send more than 1 parameter in data? or in this case it would be best to consider telephone as part of the customer DTO?

My JsonResult is trying to receive a customer and a string telephone, but telephone is null

1
  • For instance, you can send an object containing your data. Commented Sep 8, 2017 at 19:44

1 Answer 1

1

When you use JSON.stringify you need to make sure you pass in an object. So in this instance, you could do:

JSON.stringify({customer: customer, telephone: telephone})

and you could pass any information you want in that object:

JSON.stringify({customer: customer, telephone: telephone, name: 'Carl'})

Then on your server (what ever code it is, using Ruby as an example) you could access it as:

params[:customer]
params[:telephone]
params[:customer][:name]

PHP example just for fun:

$_POST['customer'];
$_POST['telephone'];
$_POST['customer']['name'];

^ I think that's still valid PHP, it's been a few years

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.