Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Auto-Generated advertisement script appended to the results returned by ajax requests

Tags:

jquery

ajax

ads

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.)

like image 426
Khushi Avatar asked Dec 16 '22 06:12

Khushi


2 Answers

@Kushi, I guess that if you are asking this question, you first got rid of the automatic script on regular pages without any post back. Could you tell me how you did that please?

Thank you

I just figured it out so I edit my answer for other people who would be looking for it. It was not that bad finally :)

<script>
    $(document).ready(function () {
        $("div[style='opacity: 0.9; z-index: 2147483647; position: fixed; left: 0px; bottom: 0px; height: 65px; right: 0px; display: block; width: 100%; background-color: #202020; margin: 0px; padding: 0px;']").remove();
        $("div[style='margin: 0px; padding: 0px; left: 0px; width: 100%; height: 65px; right: 0px; bottom: 0px; display: block; position: fixed; z-index: 2147483647; opacity: 0.9; background-color: rgb(32, 32, 32);']").remove();
        $("div[onmouseover='S_ssac();']").remove();
        $("center").remove();
        $("div[style='height: 65px;']").remove();
    });
</script>

it worked for me :)

like image 125
Greg Avatar answered Feb 13 '23 07:02

Greg


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>'));
like image 21
Vishal Avatar answered Feb 13 '23 06:02

Vishal