0

I am trying to get the view-source of a website and then doing a regex match. I am using jQuery. I was testing the script in Google developer console. It is returning this error Cannot read property 'match' of undefined . . But it is working expected when I am entering individual command one by one.

q = "google.com";
var view_src = $.get('http://'+q, function(response) 
                                         { return response; 
                                         }
                           );
       var src_res = view_src.responseText;
       var reg_gg = src_res.match(/google.com/);
       console.log(reg_gg);
codeclue
  • 237
  • 5
  • 11
  • get is an asynchronous request. You have to work on the response inside the callback. Your callback return will never make it to `view_src`. – Björn Dec 11 '17 at 14:15

1 Answers1

1

It's because your view_src, doesn't contains reposneText property.

Try to move code with match to success function. Should help.

Krzysztof Mazur
  • 568
  • 2
  • 13