I am new to AJAX. I want some help in passing large data to the server. Basically I have 100 text boxes in a form, I want to pass all this information to an asp or asp.net page, which will then process the data and respondes whether it was successfull or not.
I was thinking of creating a xml string using javascript and then sending it to the server, I am not sure if this is the right approach.
from my search I found that to pass huge data I need to use POST method, I tried it but looks like I am missing something. So it will be great help if somone could guide me or send me some working examples. In advance Thank you very much.
PeejAvery
April 2nd, 2007, 08:17 AM
I tried it but looks like I am missing something.
Well, could you post the code that you worked with? Don't forget to use code tags.
[code]
You're code here.
[/code]
As concerning examples, you can search Google. This (http://www.google.com/search?hl=en&q=ajax+post+tutorial&btnG=Google+Search) should be very helpful to you.
TejuS
April 2nd, 2007, 09:28 AM
Hello PeejAvery,
Thank you for your reply below is the code, can you please tell me where I am doing wrong??
AJAX.htm
<html>
<head>
<script src="Global.js" language="javascript"></script>
<script src="XMLWriter.js" language="javascript"></script>
<script language="javascript" type="text/javascript">
var url = "getdata.asp"; // The server-side script
function WriteTest()
{
try
{
var XML=new XMLWriter();
XML.BeginNode("Example");
XML.Attrib("SomeAttribute", "And Some Value");
XML.Attrib("AnotherAttrib", "...");
XML.WriteString("This is an example of the JS XML WriteString method.");
XML.Node("Name", "Value");
XML.BeginNode("SubNode");
XML.BeginNode("SubNode2");
XML.EndNode();
XML.BeginNode("SubNode3");
XML.WriteString("Blah blah.");
XML.EndNode();
XML.Close(); // Takes care of unended tags.
// The replace in the following line are only for making the XML look prettier in the textarea.
document.getElementById("ExampleOutput").value=XML.ToString().replace(/</g,"\n<");
}
catch(Err)
{
alert("Error: " + Err.description);
}
return false;
}
function handleHttpResponse()
{
if (http.readyState == 4) {
if (http.status == 200) {
// Use the XML DOM to unpack the city and state data
results = http.responseText
alert(results);
isWorking = false;
}
else {
alert("There was a problem retrieving the XML data:\n" + http.statusText);
}
}
}
function WriteForm(e)
{
try
{
var Frm=Settings.SrcElement(e);
var XML=new XMLWriter();
XML.BeginNode(Frm.name);
XML.Attrib("Example", "Attribute & Value");
var Nodes=Frm.elements;
for (var i=0;i<Nodes.length;i++)
XML.Node(Nodes[i].name, Nodes[i].value);
XML.EndNode();
XML.Close();
document.getElementById("ExampleOutput").value=XML.ToString().replace(/</g,"\n<");
var ExampleOutput = document.getElementById("ExampleOutput").value;
//var parameters = "ExampleOutput=" + ExampleOutput;
var parameters = "ExampleOutput=Test";
Read PeejAverys post again, especially the part about using code-tags.
- petter
PeejAvery
April 2nd, 2007, 09:42 AM
Can you please edit your post to add code tags as I told you in my first post? It makes the reading much simpler. I will review it when I get the time. Maybe someone else will beat me to it.
TejuS
April 2nd, 2007, 11:31 AM
Hey PeejAvery, sorry forgot about that I hope this is fine?? If not let me know?? Thank you
<html>
<head>
<script src="Global.js" language="javascript"></script>
<script src="XMLWriter.js" language="javascript"></script>
<script language="javascript" type="text/javascript">
var url = "getdata.asp"; // The server-side script
function WriteTest()
{
try
{
var XML=new XMLWriter();
XML.BeginNode("Example");
XML.Attrib("SomeAttribute", "And Some Value");
XML.Attrib("AnotherAttrib", "...");
XML.WriteString("This is an example of the JS XML WriteString method.");
XML.Node("Name", "Value");
XML.BeginNode("SubNode");
XML.BeginNode("SubNode2");
XML.EndNode();
XML.BeginNode("SubNode3");
XML.WriteString("Blah blah.");
XML.EndNode();
XML.Close(); // Takes care of unended tags.
// The replace in the following line are only for making the XML look prettier in the textarea.
document.getElementById("ExampleOutput").value=XML.ToString().replace(/</g,"\n<");
}
catch(Err)
{
alert("Error: " + Err.description);
}
return false;
}
function handleHttpResponse()
{
if (http.readyState == 4) {
if (http.status == 200) {
// Use the XML DOM to unpack the city and state data
results = http.responseText
alert(results);
isWorking = false;
}
else {
alert("There was a problem retrieving the XML data:\n" + http.statusText);
}
}
}
function WriteForm(e)
{
try
{
var Frm=Settings.SrcElement(e);
var XML=new XMLWriter();
XML.BeginNode(Frm.name);
XML.Attrib("Example", "Attribute & Value");
var Nodes=Frm.elements;
for (var i=0;i<Nodes.length;i++)
XML.Node(Nodes[i].name, Nodes[i].value);
XML.EndNode();
XML.Close();
I am not sure if this is the way you wanted the code? if not can you just give me an example?? actually this the first time I am using the forum, so not familiar with the terminologies or tags, by mistake I think I skiped [/code] (sorry about that).
I want to send say like 100 of fields data to the server which will process and return me just one message as successfull or not. I am not sure if the server is getting whatever information I sent. So to cross check I was just trying to display the message I sent.
ajax.htm code
<html>
<head>
<script src="Global.js" language="javascript"></script>
<script src="XMLWriter.js" language="javascript"></script>
<script language="javascript" type="text/javascript">
var url = "getdata.asp?param="; // The server-side script
function WriteTest()
{
try
{
var XML=new XMLWriter();
XML.BeginNode("Example");
XML.Attrib("SomeAttribute", "And Some Value");
XML.Attrib("AnotherAttrib", "...");
XML.WriteString("This is an example of the JS XML WriteString method.");
XML.Node("Name", "Value");
XML.BeginNode("SubNode");
XML.BeginNode("SubNode2");
XML.EndNode();
XML.BeginNode("SubNode3");
XML.WriteString("Blah blah.");
XML.EndNode();
XML.Close(); // Takes care of unended tags.
// The replace in the following line are only for making the XML look prettier in the textarea.
document.getElementById("ExampleOutput").value=XML.ToString().replace(/</g,"\n<");
}
catch(Err)
{
alert("Error: " + Err.description);
}
return false;
}
function handleHttpResponse()
{
if (http.readyState == 4) {
if (http.status == 200) {
// Use the XML DOM to unpack the city and state data
results = http.responseText
alert(results);
isWorking = false;
}
else {
alert("There was a problem retrieving the XML data:\n" + http.statusText);
}
}
}
function WriteForm(e)
{
try
{
var Frm=Settings.SrcElement(e);
var XML=new XMLWriter();
XML.BeginNode(Frm.name);
XML.Attrib("Example", "Attribute & Value");
var Nodes=Frm.elements;
for (var i=0;i<Nodes.length;i++)
XML.Node(Nodes[i].name, Nodes[i].value);
XML.EndNode();
XML.Close();
document.getElementById("ExampleOutput").value=XML.ToString().replace(/</g,"\n<");
var passValue;
passValue = "Params='"+document.getElementById("ExampleOutput").value+"'";
<%
Dim val
val = request.Form("ExampleOutput")
response.write(val & "--Success")
%>
PeejAvery
April 3rd, 2007, 08:42 AM
I personally have never worked with XMLWriter() before. If I am not mistaken it is IE only. Am I correct? Why not just use createElement() and appendChild()?
TejuS
April 3rd, 2007, 09:57 AM
Yes thats right I have HTML pages with javascript, I need to capture data from 100s fields values send it to the webservice and the get the result as successfull or not.
Since the data is huge, I thought I will create a XMLstring and post it to the server. Then get back a text message.
I thought I will create an xml file or text file and dump all the data. Then pass the file name to the server, which can then go into that file take the data and process. Then I found that from javascript I will not be able to create a new file, I can only make changes to already created file.
Basically my requirement is I have HTML pages and from which I need to send huge data to webservice and get an answer. I did some re-search on the net and based on other developers comments I assumed AJAX would be the best option. I am not sure if I am thinking right.. can you suggest which is the best way to go about it??
It will be of great help to me.
Thanks for all your patience - T
PeejAvery
April 3rd, 2007, 10:19 AM
Take a look at the following script. You can easily adapt it to what you want. When forming the parameters, just use a for loop to read through the input's values.