0

I have a list which contains various docIds. When the information is to be submited, a JQuery function is called which then collects all of the list values. I then need these list values to be sent via Ajax to a classic ASP page where the values will be formatted and then sent back to the original page to then populate a textarea. Here is my JQuery code:

$("#create").click(function() {

    var strDocIDs = $.map($('.doc_list:visible').find('li[value]'), function(li) { return $(li).attr("value") }).join(",");
    alert(strDocIDs);

    $.ajax({
           type: "GET",
           url: "newslettercreate_action.asp",
           data: { strDocIDS: strDocIDs },
           success: function(result) {
               var newsletter_string = $(result);
               $("#scratch").val(newsletter_string);
               }
        }); 
});

And my ASP code:

result = Request("strDocIDs")

The information that I get returned into my textarea is:

[object Object]

My form method is currently set to POST. And would it matter between my using a submit button vs a traditional button to trigger the function?

2 Answers 2

1

Because you are wrapping the response in $ and it become and object. Remove that line and it will work, If your ASP page is returning some content.

And I am sure you may want to stop the default behaviour of the button click by calling thte preventDefault method

$(function(){

   $("#create").click(function(e) {
      e.preventDefault();

      var strDocIDs = $.map($('.doc_list:visible').find('li[value]'), function(li) { return $(li).attr("value") }).join(",");
      alert(strDocIDs);

       $.ajax({
           type: "GET",
           url: "newslettercreate_action.asp",
           data: { strDocIDS: strDocIDs },
           success: function(result) {              
              $("#scratch").val(result);
            }
       });
   });

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

5 Comments

This seems to have gotten me a step closer but for some reason the value that is returned is not the value of strDocIDs but it appears to be one an include file on the ASP page. This caught me off guard.
@Yuschick Use firebug to see what value is coming back from the ASP page
It looks like the right information is being passed but the "Response" according to Firebug is the include file that I keep seeing which is a lot of CSS and some other JS information. So weird!
Could the commas in my string which are being converted to %2C be causing a conflict?
@Yuschick: No. I guess you need to make sure your ASP page is behaving as expected ( returning a proper response to the calle)
1

The result of $(result) is a jQuery result object. When you try to set this with .val(), the JavaScript engine is serializing it as [object Object].

So the question is, what is result supposed to contain? Is it text? JSON? HTML? The answer to that question will drive the right way to inject it.

If it's just a string, then this should do it:

$("#scratch").val(result);

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.