Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send multiple data fields via Ajax? [closed]

Tags:

jquery

ajax

sql

People also ask

How can I send multiple values in Ajax POST?

click(function() { var status = $("#activitymessage"). val(); var name = "Ronny"; $. ajax({ type: "POST", url: "ajax/activity_save. php", **data: "status="+status+"name="+name"**, success: function(msg) {...

How pass multiple values from php to AJAX?

function getInfo(val1, val2) { $. ajax({ type: "POST", url: "get_info. php", data: 'value1='+val1+'&value2'+val2, success: function(data){ $("#info"). html(data); } }); };

How do you send Ajax request every 5 seconds?

Use just setTimeout(executeQuery, 5000); instead of setTimeout('executeQuery()', 5000); - it's shorter and faster.


The correct syntax is:

data: {status: status, name: name},

As specified here: http://api.jquery.com/jQuery.ajax/

So if that doesn't work, I would alert those variables to make sure they have values.


You can send data through JSON or via normal POST, here is an example for JSON.

 var value1 = 1;
 var value2 = 2;
 var value3 = 3;   
 $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: "yoururlhere",
      data: { data1: value1, data2: value2, data3: value3 },
      success: function (result) {
           // do something here
      }
 });

If you want to use it via normal post try this

 $.ajax({
      type: "POST",
      url: $('form').attr("action"),   
      data: $('#form0').serialize(),
      success: function (result) {
         // do something here
      }
 });

Try with quotes:

data: {"status": status, "name": name}

It must work fine.


var countries = new Array();
countries[0] = 'ga';
countries[1] = 'cd';

after that you can do like:

var new_countries = countries.join(',')

after:

$.ajax({
    type: "POST",
    url: "Concessions.aspx/GetConcessions",
    data: new_countries,
    ...

This thing work as JSON string format.


According to http://api.jquery.com/jquery.ajax/

$.ajax({
  method: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
  alert( "Data Saved: " + msg );
});