Тема: Making a Ajax request and manipulate the text

Hi,

I'm looking for a way to make a page request in Ajax and retrieve the request page to a string. This string should be available to any function but in the example below it isn't because alert(data); doesn't popup. After converting to a string i want to manipulate the text by using "find" to look for a string or a text in a determined area. Can this be done?

<input type="text" id="http" value="http://www.example.com">
<br>
<input type="button" id="submit" onclick="myhttp()" value="Send!"/>
<script>
    function myhttp() {
        var http = document.getElementById("http").value;
        var dataString = 'lsd=AVrls4dL&email=email@gmail.com';

        $.ajax({
            type: "GET",
            url: http,
            data: dataString,
            async: false,
            success: function(data){
                alert(data);
            }
        });
            
    }
</script>

Thanks

2 Востаннє редагувалося Engineer (18.10.2018 22:19:57)

Re: Making a Ajax request and manipulate the text

You can update your code and add error handler for catch the problems

<input type="text" id="http" value="http://www.example.com">
<br>
<input type="button" id="submit" onclick="myhttp()" value="Send!"/>
<script>
    function myhttp() {
        var http = document.getElementById("http").value;
        var dataString = 'lsd=AVrls4dL&email=email@gmail.com';
 
        $.ajax({
            type: "GET",
            url: http,
            data: dataString,
            async: false,
            success: function(data){
                alert(data);
            },
                error: function (data) {
                    alert(data.statusText);
                    alert(data.responseText);
                }
        });
            
    }
</script>
Подякували: leofun011

3

Re: Making a Ajax request and manipulate the text

Hi, using your error handler gives 2 messages, "NetworkError: A network error occured." for data.statusText and "undefined" for data.responseText.

The get request is made succeffully as you can see below

https://i.imgur.com/d6Edy21.jpg

But what i really want is to cache or something similar all text presented in the page and convert to a string to show the info to the user.

4

Re: Making a Ajax request and manipulate the text

As for me you have an issue with cross-domain http request.
Please see https://stackoverflow.com/questions/150 … query-ajax for more details

5

Re: Making a Ajax request and manipulate the text

Прихований текст
Moved to English, c 1.1
x
Подякували: leofun011