jan
Posts: 0
Joined: Sat Aug 09, 2014 7:05 pm

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

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

jan
Posts: 0
Joined: Sat Aug 09, 2014 7:05 pm

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

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?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

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

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

jan
Posts: 0
Joined: Sat Aug 09, 2014 7:05 pm

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

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

jan
Posts: 0
Joined: Sat Aug 09, 2014 7:05 pm

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

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

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

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

jan
Posts: 0
Joined: Sat Aug 09, 2014 7:05 pm

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

it works, thanks a lot.

Return to “Issues”