how to get access to remote pages using javascript via php proxy script
how to get access to remote pages using javascript via php proxy script
There follow the code ; just paste it in your server main folder and you can get the access to webpages via remote routine
01.
$(
function
(){
02.
03.
// handle this by submit form.
04.
$(
'#params'
).submit(
function
(){
05.
var
proxy =
'../../blah_name.php'
,
06.
url = proxy +
'?'
+ $(
'#params'
).serialize();
07.
08.
// use the right contnet
09.
$(
'#request'
).html( $(
'<a/>'
).attr(
'href'
, url ).text( url ) );
10.
$(
'#response'
).html(
'Loading...'
);
11.
12.
// you now check it to see it is working
13.
if
( /mode=native/.test( url ) ) {
14.
15.
// making it right way
16.
$.get( url,
function
(data){
17.
18.
$(
'#response'
)
19.
.html(
'<pre/>'
)
20.
.find(
'pre'
)
21.
.text( data );
22.
23.
SyntaxHighlighter.highlight();
24.
});
25.
26.
}
else
{
27.
28.
// now working for json
29.
$.getJSON( url,
function
(data){
30.
31.
$(
'#response'
)
32.
.html(
'<pre/>'
)
33.
.find(
'pre'
)
34.
.text( JSON.stringify( data,
null
, 2 ) );
35.
36.
SyntaxHighlighter.highlight();
37.
});
38.
}
39.
40.
// Prevent default form submit action.
41.
return
false
;
42.
});
43.
44.
// Submitting url the form on page load if ?url= is passed into the example page.
45.
if
( $(
'#url'
).val() !==
''
) {
46.
$(
'#params'
).submit();
47.
}
48.
49.
// Disable AJAX caching.
50.
$.ajaxSetup({ cache:
false
});
51.
52.
// Disable dependent checkboxes as necessary.
53.
$(
'input:radio'
).click(
function
(){
54.
var
that = $(
this
),
55.
c1 =
'dependent-'
+ that.attr(
'name'
),
56.
c2 = c1 +
'-'
+ that.val();
57.
58.
that.closest(
'form'
)
59.
.find(
'.'
+ c1 +
' input'
)
60.
.attr(
'disabled'
,
'disabled'
)
61.
.end()
62.
.find(
'.'
+ c2 +
' input'
)
63.
.removeAttr(
'disabled'
);
64.
});
65.
66.
// Clicking sample remote urls should populate the "Remote URL" box.
67.
$(
'#sample a'
).click(
function
(){
68.
$(
'#url'
).val( $(
this
).attr(
'href'
) );
69.
return
false
;
70.
});
71.
});