Page 1 of 1

Read the source of any web page with Javascript on Server Code

Posted: Sat Aug 09, 2014 7:19 pm
by jan

hi! I am newbie to javascript.
i am trying to read the source of url but it isn't working.
code
var content = $.getJSON("http://pastebin.com/raw.php?i=PPiy6zwq");
// format as JSON and return the response
response.success(content, "application/json");
/code


Read the source of any web page with Javascript on Server Code

Posted: Sat Aug 09, 2014 7:28 pm
by Illya Stepanov

Hi -

Please check this thread: https://getsatisfaction.com/apperyio/...


Read the source of any web page with Javascript on Server Code

Posted: Sat Aug 09, 2014 7:59 pm
by jan

error in trace tab

ReferenceError: $ is not defined ( @ 1 : 14 ) - var content = $.getJSON("http://pastebin.com/raw.php?i=PPiy6zwq");

What am I doing wrong?


Read the source of any web page with Javascript on Server Code

Posted: Sat Aug 09, 2014 8:05 pm
by Illya Stepanov

Where do you run this code? Can you show the full error message screenshot.


Read the source of any web page with Javascript on Server Code

Posted: Sat Aug 09, 2014 8:15 pm
by jan

script on server code
codevar content = $.get("http://pastebin.com/raw.php?i=PPiy6zwq");

// format as JSON and return the response
response.success(content, "application/json");/code

full error message:
Image


Read the source of any web page with Javascript on Server Code

Posted: Sat Aug 09, 2014 8:25 pm
by jan

i changed this code
var content = $.get("http://pastebin.com/raw.php?i=PPiy6zwq");
// format as JSON and return the response
response.success(content, "application/json");

this code running on server code


Read the source of any web page with Javascript on Server Code

Posted: Mon Aug 11, 2014 3:46 am
by Yurii Orishchuk

Hi Jan,

Here is code example:

pre

var responseBody = {},
requestParams = {},
paramKeys = request.keys();

for (var key = 0; key < paramKeys&#46;length; key++) {
requestParams[paramKeys[key]] = request&#46;get(paramKeys[key]);
}

&#47;&#47;Note you need to change site url here&#46;
var siteUrl = "http:&#47;&#47;wiki&#46;org/";
var requestBody = "";

var XHRResponse = XHR&#46;send("GET", siteUrl,
{
"status": "sent",
"headers": {
},
body: requestBody
}
);

console&#46;log(XHRResponse);

console&#46;log(XHRResponse&#46;body);

responseBody = XHRResponse&#46;body;

response&#46;success(responseBody, "application/json");

/pre

See details: http://prntscr.com/4bmiea/direct

Regards


Read the source of any web page with Javascript on Server Code

Posted: Mon Aug 11, 2014 12:56 pm
by jan

it works, thanks a lot.