Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to handle ajax response

Posted on 2008-06-17
6
Medium Priority
?
234 Views
Last Modified: 2010-05-18
Hello Experts,
I am returning comma separated columns and pipe separated in the Ajax Response.
I have a SELECT tag in the page where user can select which column they want to use in the report,
How can I handle this !
Please advice.
Thanks
Sam
0
Comment
Question by:newbie27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 600 total points
ID: 21803151
Like this:

<script>
function yourResponseFunction(){
  var theResponse = http.responseText;
  var theColumnNumber = document.forms[0].yourSelectName.value; // option value has to be column Number,  first column number zero
  var row = theResponse.split("|");
  for(var i=0;i<row.length;i++){
     var column = row[i].split(",");
     alert("Row"+i+"Column"+theColumnNumber+":  "+column[theColumnNumber]);
  }
}

</script>

0
 
LVL 8

Author Comment

by:newbie27
ID: 21803280
Hello Zvonko,
Thanks for your comment, I mean if you could please follow this
http://213.253.134.6/artism/admin/list_admin.asp 
user details: lau/lau
chose any 2 items from the page and click on export to actually see the page I am working on
hopefully you may understand what I am trying to do there.
thanks
sam
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21803391
Are you talking about this page:
http://213.253.134.6/artism/admin/list_export.asp

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Author Comment

by:newbie27
ID: 21803426
Yes, on this page I am doing an ajax call to retrieve details for the records submitted from list_admin.

Attached is the Asp script to process the Ajax request
rURL = RemoteServer & "/xmla/xml_results.asp?DBM=" & SiteName & "&SF1=keyword&ST1=" & ISBNLists							
			xTxt = GetXML(rUrl)
			'parts = Split(XMLField(xTxt, "resultfields", False), chr(28)) 
			parts = Split(XMLField( Replace(xTxt,",","&#44;"), "resultfields", False), chr(28))
            For each p in parts
			   strISBNData = strISBNData &  XMLField(p, "fv_co_name", false) & ","
			   strISBNData = strISBNData &  XMLField(p, "fv_co_address", false) & ","
			   strISBNData = strISBNData &  XMLField(p, "fv_co_descrip", false) & ","
			   strISBNData = strISBNData &  XMLField(p, "fv_co_tel_work", false) & ","
			   strISBNData = strISBNData &  XMLField(p, "fv_pe_name", false) & ","
			   strISBNData = strISBNData &  XMLField(p, "fv_pe_position", false) & ","
			   strISBNData = strISBNData &  XMLField(p, "fv_pe_tel_work", false) & ","
			   strISBNData = strISBNData &  XMLField(p, "fv_ref_no", false) & "|"			   
			next   
			response.Write strISBNData		

Open in new window

0
 
LVL 82

Accepted Solution

by:
hielo earned 1400 total points
ID: 21811902
From your description, you stated that you have a formatted response and a select tag with options. Then your question is "How can I handle this !" What's the problem/goal?

If you are submitting an ajax request you will need a call back function that will receive the response text. You can split that text at the commas and if what you are trying to do is to "rebuild" the <SELECT> then wrap the <select> in some container tag:
<span id="selContainer"><select name="theList">...</select></span>

 and then insert a new html in that span so that it contains the entire <select> (not just the options)

...
 success=function (msg)
  {
    var sel="";
    var data = msg.split("|");
    if( data.length)
    {
    sel = "<select name='theList'>";
    for(var i=0; i < data.length; ++i)
    {
        var t = data[i].split(",")
        sel += '<option value="' + t[0] + '">' + t[1] + '</option>';
   }
    sel+='</select>';
   $("#selContainer").html(sel);
   }
  }
0
 
LVL 8

Author Closing Comment

by:newbie27
ID: 31467954
thanks
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question