Reputation: 2732
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?
Upvotes: 0
Views: 2329
Reputation: 11042
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);
Upvotes: 1
Reputation: 218882
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);
}
});
});
});
Upvotes: 1