Click here to Skip to main content
15,909,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello frnds,

I want to get html source of particulate url by using ajax call,

till I have done,

JavaScript
url: "http://google.com",
         type: "GET",
         dataType: "jsonp",
         context: document.doctype
     }).done(function (data) {
         alert(data);
     });


but in this code its give error,

JavaScript
SyntaxError: syntax error

<!doctype html><html itemscope="" itemtype="http://schema.or



I want to read html from this call,

How can I achive this , or any other way to do like this?

Thanks in advance
Posted
Updated 23-Mar-14 22:31pm
v2

The page coming back from Google is not going to be jsonp. Try "html" as the dataType instead, if you want to load html.
 
Share this answer
 
Comments
ExpertITM 29-Mar-14 12:56pm    
hi,
I have try with datatype html/text, but its not load. responce is 200 ok but it gives empty responce,
Can you give me any code for the same
Thanks
You have take the json object data Type , but the google url doesn't give you that type and as well as HTML
So you can try that type of html and try to extract the data
 
Share this answer
 
Comments
ExpertITM 29-Mar-14 12:58pm    
hi,
I have try with datatype html/text, but its not load. responce is 200 ok but it gives empty responce,
Can you give me any code for the same
Thanks
One thing I forgot to tell you, it is not possible to get the source code of any file like php , html ...etc

JavaScript
$("123.php",function(data){
    alert(data);
});


It is restricted in ajax and also in jquery , because

If You try to "alert(data)" that means whole source code is revealed , if it is php then it may be security problem.
 
Share this answer
 
Comments
Trajan McGill 31-Mar-14 10:42am    
Of course you can get the source code of an HTML file, because that's what is sent to the browser. The reason you can't get source for PHP or some other executable has nothing to do with ajax or jquery. It is because the server doesn't send the code, it sends the output from running the code, which is (usually) HTML.
ExpertITM 13-Apr-14 12:19pm    
hello, I dont want php code. I just need html contant i.e. page source. I am not hacker!!
Thanks
try this.....

C#
HttpWebRequest request = (HttpWebRequest)WebRequest.Create
            ("http://www.YourSiteUrl.com");

            //Method GET
            request.Method = "GET";

            //HttpWebResponse for result
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();


            //Mapping of status code
            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream receiveStream = response.GetResponseStream();
                StreamReader readStream = null;

                if (response.CharacterSet == "")
                    readStream = new StreamReader(receiveStream);
                else
                    readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));

                //Get news data in json string
                //You will get html source here......
                string data = readStream.ReadToEnd();
             }



You will get source code in data string
 
Share this answer
 
Comments
ExpertITM 13-Apr-14 12:17pm    
hello, I want to get by using only jquery or js. I cant use c# code for it
Thanks.
Nirav Prabtani 13-Apr-14 14:01pm    
You can dufined it as static string function and call it from ajax post method from js.

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