开发者

receive a responseText in ajax but without div tag

开发者 https://www.devze.com 2022-12-27 18:56 出处:网络
I want to know if there is any other way without using a div tag to receive response html when sending parameter whith ajax.

I want to know if there is any other way without using a div tag to receive response html when sending parameter whith ajax. I'am asking because when I am building 开发者_如何学编程the select in other servlet and returning the result to jsp it receive the responsehtml in a div tag when we use the famous:

x = xhr.responseText;
document.getElementById('param').innerHTML = x;

with param is the id of div tag. Note: <div id="param" style='display:inline'> this works fine when populating ddl but its constraint are multiple for my case.

Thinks.


Give the id param to any element you want to use instead of the div and response will be shown in that element.


If I understand you correct you don't want to have a dummy div element only to be able to place inside a html fragment received from ajax. In this case you can build you element directly and insert befor or after a real DOM element which you already have. The code can looks like following

jQuery('#select_id').remove(); // if not exists this line makes nothing
var htmlfragment = '<div id="select_id">';
htmlfragment += x; // place data with select element received from ajax call
htmlfragment += '</div>';
jQuery(htmlfragment).insertBefore("#myexistingelement");
0

精彩评论

暂无评论...
验证码 换一张
取 消