Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
it's my ajaxcode :
HTML
$.ajax(
               {
                   type: "POST",
                   url: "didan.asmx/sending",
                   data: { st: $(".myInput").attr('id') },
                   dataType: "text",
                   success: accessfn(result),
               }
                              )
        }
        

        function accessfn(result) {
            
            $("#divmess").append(result);
        }

"result" content is:
HTML
<input id="el12" value="tax" type="button" />

but by:
HTML
            $("#divmess").append(result);
//or
            $("#divmess").html(result);

it doesn't make visual button and just append exactly " <input class="myInput" id="aca" value="tax" type="button" />" string end of div.
thanks all
Posted
Comments
xszaboj 14-Aug-15 11:04am    
why is result different than appended element? is that a mistake in answer or is that what is really append to div?
Afzaal Ahmad Zeeshan 14-Aug-15 13:23pm    
The function actually does work, what doesn't work is the content being passed. There is some encoding going on, maybe on your service side or someone in the networking. Please see my answer, Solution 2 to get an answer to your problem.

1 solution

I will doubt that the content is not in HTML format. The problem is that your content's response that is returned is in encoded format. That is why the problem occurs. The content is written directly as string. Because, (IMO) < and/or > are encoded as &lt; and &gt;. Thus when the browser gets the values, it considers them as string (not HTML) but when it renders them. It turns them in their actual representation rather than this encoded representation.

As a proof to my claim (because I don't have the source code to your application) I have created a fiddle for you. In that fiddle I have used two types of codes, and they do the same thing what you have referenced.

JavaScript
$('#decode').click(function () {
    $('#paragraph').append('<input type="text" />');
});

$('#encode').click(function () {
    $('#paragraph').append('&lt;input type="text" /&gt;');
});


This code was exected over this HTML

HTML
<p id="paragraph"></p>

<button id="decode">HTML content</button>
<button id="encode">HTML encoded HTML</button>


The result was same, in case of decoded click, there was a new input element, but in other case there was a plain-text string being rendered on the screen. As a live example: http://jsfiddle.net/afzaal_ahmad_zeeshan/w7rf2mc8/[^]

I hope you get the point. If that is ASP.NET, you may consider using the Html.Raw() while rendering the content because it converts such encoded strings to HTML entities and brackets.
 
Share this answer
 
Comments
mohamadMahmodi 14-Aug-15 14:12pm    
Thank you Afzaal but infact i try to result caled back via httputility.htmlencod and htmldecode asp methodes that "sending" class is in ".cs" file of asmx in App_code folder
Afzaal Ahmad Zeeshan 14-Aug-15 14:40pm    
You may consider debugging your application because it is not sure what causes the problem. I am sure the problem is this. But where is it being caused is not clear.
mohamadMahmodi 14-Aug-15 16:19pm    
ya i think so, how i using html.Raw()? my project is on webform and i included system.web.mvc ,which another method can help me?
and is a ajax way to convert or encoding "result" in client side? because i said , "result" is exactly "<input type="text" />"
mohamadMahmodi 14-Aug-15 17:38pm    
hey Afzaal you did correct,i debuged in Firebug and "result" content is include "&'lt" and "&'gt" end and start of
"input type="button" ",
how i fix it in ajax region clint sid?
Afzaal Ahmad Zeeshan 15-Aug-15 5:03am    
You will be able to find a good decoder or encoder, if you still don't find any. Consider using content.Replace(">", ">").Replace("<", "<") and replace them yourself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900