My site is hosted on somee.com.
I have used JQuery to send ajax requests.
On every ajax request the returned result is appended with the below text.
"<!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE-->
<center><a href="http://somee.com">Web hosting by Somee.com</a></center> </textarea>
</xml></script></noframes></noscript></object></layer></style></title></applet>
<script language="JavaScript"
src="http://ads.mgmt.somee.com/serveimages/ad2/WholeInsert4.js"></script>
<!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE-->"
for example if on success of ajax call the server returns the following string : "Invalid Username and/or Password"
Then I get the following string :
"Invalid Username and/or Password <!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE-->
<center><a href="http://somee.com">Web hosting by Somee.com</a></center> </textarea>
</xml></script></noframes></noscript></object></layer></style></title></applet>
<script language="JavaScript"
src="http://ads.mgmt.somee.com/serveimages/ad2/WholeInsert4.js"></script>
<!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE-->"
Now I am comparing this string to the other string, So comparison returns false as this string contains the appended text.
Thus, my site is not functioning properly.
EDIT :
I counted the no. of characters and tried to use .slice(0, -no. of characters in advertisement)
. This works fine if the server returns string. But does not work while server returns 'JSON'
because in the ajax call we have to declare dataType:'json'
and after the addition of advertisement script the result is no more json object. So, Success is not called and as a result I did not get the output.
So, now my question is : If server returns JSON + String
on AJAX call, on client side I want to delete the String part
and get only the JSON
object so that AJAX call returns in a success instead of failure/Error. (I know the no. of characters that the appended string contains.)
Then don't use datatype attribute, instead you should use jQuery.parseJSON.
Here is the example:
$.ajax({
url: "/members/GetAllFileNamesOfSelectedUser?SelectedUserName=" + $("#AllowedFriends").find(":selected").text(),
//dataType: 'json',
success: function (FileNamesUnparsed) {
var FileNames = jQuery.parseJSON(FileNamesUnparsed.slice(0, -369));
$(".item").remove();
$.each(FileNames, function (key, value) {
$('#fileName').append($('<div class="item"><span>' + FileNames[key] + '</span> <img id="imgDelete" title = "Delete" src = "../Images/delete.png" /> </div>'));