AJAX – multiple data

I’m stuck, i’m trying to submit a form using AJAX, but I can’t find a way to send multiple data fields via my AJAX call. $(document).ready(function() $(“#btnSubmit”).click(function() var status = $(“#activitymessage”).val(); var name = “Ronny”; $.ajax( type: “POST”, url: “ajax/activity_save.php”, **data: “…

via Sql Databases Development » Search Results » ajax:

AJAX – multiple data

I’m stuck, i’m trying to submit a form using AJAX, but I can’t find a way to send multiple data fields via my AJAX call.
$(document).ready(function()
$(“#btnSubmit”).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) …i’ve tried all sorts of stuff:
data: status: status, name: name,or even stuff like this just for testing purposes:
data: “status=testing&name=ronny”,But whatever I try, I get nothing in my activity_save.php thus nothing in my SQL. So, what’s the correct syntax to put more lines of data in my AJAX call?
………………………………………

The correct syntax is: http://api.jquery.com/jQuery.ajax/
data: status: status, name: name,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 somthing 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 somthing here

});hope it helps.
………………………………………

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.
………………………………………

I am new to AJAX and i have tried this and its work well
function q1mrks(country,m)

// alert(“hellow”);
if (country.length==0)

//alert(“hellow”);
document.getElementById(“q1mrks”).innerHTML=””;
return;

if (window.XMLHttpRequest)
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();

else
// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);

xmlhttp.onreadystatechange=function()

if (xmlhttp.readyState==4 && xmlhttp.status==200)

document.getElementById(“q1mrks”).innerHTML=xmlhttp.responseText;

}
xmlhttp.open(“GET”,”../location/cal_marks.php?q1mrks=”+country+”&marks=”+m,true);

//mygetrequest.open(“GET”, “basicform.php?name=”+namevalue+”&age=”+agevalue, true)
xmlhttp.send();
}

For more info: AJAX – multiple data

Sql Databases Development » Search Results » ajax

AJAX – multiple data

Share this post:

Related Posts

Leave a Comment