Frank February 2016

Why am I getting the html tags from jQuery and HttpHandler?

I have the following code :

 <script>
 $(document).on('click','#Save',function()
 {
   $.get('My_App?New_Info='+$('button[id^=\"Current_\"]').text(),function(responseText)
   {
     $('#Page_div').text(responseText);
   });
 });
 </script>

The html looks like this :

<div id=Page_div>
      <Table Border=1>
        <Tr>
          <Td><button id=Current_1 type=button></button></Td>
          <Td><button id=Current_2 type=button></button></Td>
          <Td><button id=Current_3 type=button></button></Td>
          <Td><button id=Current_4 type=button></button></Td>
          <Td><button id=Current_5 type=button></button></Td>
          <Td><button id=Current_6 type=button></button></Td>
          <Td><button id=Save type=button>Save</button></Td>
        </Tr>
      </Table>
</div>

And the HttpHandler code looks like this :

  public void handle(HttpExchange exchange)
  {
    OutputStream responseBody=exchange.getResponseBody();
    String requestMethod=exchange.getRequestMethod(),requestPath=exchange.getRequestURI().getPath(),title="ABC",
             New_Info,responseString="<Html>\n<Head>\n  <Title>"+title+"</Title>\n</Head>\n<Body BgColor=#FDF5E6>\n<Center>\n"+Get_jQuery()+"\n\n";
    LinkedHashMap<String,String> params=queryToMap(exchange.getRequestURI().getRawQuery());
    File file;

    try
    {
      New_Info=(params.get("New_Info")==null?null:URLDecoder.decode(params.get("New_Info"),"utf-8"));

      if (New_Info!=null)                                                                    // After Save button is clicked, save new user info
      {
        Headers responseHeaders=exchange.getResponseHeader        

Answers


Quentin February 2016

text() means "Treat the content as plain text".

If you want to treat it as HTML source code then use html() instead.

Post Status

Asked in February 2016
Viewed 3,170 times
Voted 9
Answered 1 times

Search




Leave an answer