AJAX with jsp and servlet



我的JSP页面带有一个表格。

<form name="contact" action="">  
            <fieldset>  
                <div id="res"></div>
                <label for="name" id="name_label">Name</label>  
                <input type="text" name="name" id="name" size="30" value="" class="text-input" />  
                <label class="error" for="name" id="name_error">This field is required.</label>  
                <label for="email" id="email_label">Return Email</label>  
                <input type="text" name="email" id="email" size="30" value="" class="text-input" />  
                <label class="error" for="email" id="email_error">This field is required.</label>  
                <label for="phone" id="phone_label">Return Phone</label>  
                <input type="text" name="phone" id="phone" size="30" value="" class="text-input" />  
                <label class="error" for="phone" id="phone_error">This field is required.</label>  
                <br />  
                <input type="submit" name="submit" class="button" id="submit_btn" value="Send" />  
            </fieldset>  
        </form> 
<div id="res"></div>

和一个按钮的ajax

 $.ajax({
                    type: "POST",
                    url: "processServlet",
                    data: dataString,
                    success: function(data) {
                        $('#res').wrap(data);
                    }
                });
                return false;
            });

,在servlet中,我有具有HTML标签的字符串

 String te="<div class="input-control text" n" +
"                                         data-role="datepicker" n" +
"                                         data-week-start="1"n" +
    "                                         data-format='m/d/yyyy'n" +
"                                         data-effect='slide'>n" +
"                                        <input type="text" placeholder="Date purchased" 
          name="DATEPURCHASED" id="DATEPURCHASED">n" +
     "                                        <button class="btn-date" disabled></button>n" +

";

        out.println(te);

Servlet将日期选择器返回JSP页面。当datepicker显示在JSP页面中时,datePicker似乎不起作用?我在做什么错?我需要将整个HTML文件返回页面吗?看起来他们没有共享主JSP页面的CSS和JS。

$('#res').html(data)将将DIV的innerHTML设置为变量data的内容。

$('#res').wrap(data)试图将data的内容包裹在Div。

周围

如果要围绕所有段落,请使用.wrap()

$( "p" ).wrap( "<div></div>" );

如果要将某些内容放在Div中,请使用.html()

最新更新