10 Replies - 1781 Views - Last Post: 26 March 2012 - 08:19 AM

#1 Asperant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 05-November 11

ajax does not work on my hosting

Posted 25 March 2012 - 09:03 AM

Hi!

Simple example:

Script with ajax-request (by jQuery lib)
function captchaWork()
{
alert("Check before request");//ok
$.post("check.php",obrabotka);
}
 
function obrabotka(data)
{
alert("Function obrabotka");
}



Server php-script (check.php)
<?php
echo json_encode('ok');
?>




Problem description: if the php-script is on a local computer (with local apache) everything works fine. But if the php-script is on a hosting, it does not respond to the ajax-request. (although, if I enter path to the script in address field - the script gives the string "ok").

I tried to do different things in order to solve the problem (to change encoding of the files, to change a hosting provider), but all of them don't help.

My question: What can be wrong with my example?

Thank You

Is This A Good Question/Topic? 0
  • +

Replies To: ajax does not work on my hosting

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: ajax does not work on my hosting

Posted 25 March 2012 - 09:12 AM

since AJAX is a client side technology, the only interference comes from the SOP.
Was This Post Helpful? 1
  • +
  • -

#3 Asperant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 05-November 11

Re: ajax does not work on my hosting

Posted 25 March 2012 - 09:30 AM

View PostDormilich, on 25 March 2012 - 09:12 AM, said:

since AJAX is a client side technology, the only interference comes from the SOP.


I don't think so, because all scripts are on the hosting (the same domain). And the example does not work anyway...
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: ajax does not work on my hosting

Posted 25 March 2012 - 10:21 AM

is there anything in the Error Console? otherwise a link to the page in question would be helpful.
Was This Post Helpful? 0
  • +
  • -

#5 Asperant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 05-November 11

Re: ajax does not work on my hosting

Posted 25 March 2012 - 11:13 AM

View PostDormilich, on 25 March 2012 - 10:21 AM, said:

is there anything in the Error Console? otherwise a link to the page in question would be helpful.


It started working on the hosting!!! http://www.vibrohard...x.php/otrabotka (to test - push button "Проверить" , the first message will appear before ajax-request and the second - after server-reply).

BUT, when I test my JS with ajax-request on another server it does not get reply from the server.

Please, could you try it:

function captchaWork()
{
alert("Проверка перед ajax-запросом HOSTING");
$.post("http://www.vibrohardening.ru/MyData/captcha/check.php",obrabotka);
}

function obrabotka(data)
{
alert("Функция obrabotka "+data);
}


Was This Post Helpful? 0
  • +
  • -

#6 Asperant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 05-November 11

Re: ajax does not work on my hosting

Posted 25 March 2012 - 11:24 AM

and this is test page:


<head>
<script type="text/javascript" src="jQuery.js"></script>
<script type="text/javascript" src="captcha_ajax.js"></script>
</head>


<body>
<button onclick='captchaWork();'>Text</button>
</body>



captcha_ajax.js - code with ajax-request
jQuery.js - library
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,226
  • Joined: 08-June 10

Re: ajax does not work on my hosting

Posted 25 March 2012 - 01:11 PM

View PostAsperant, on 25 March 2012 - 08:13 PM, said:

BUT, when I test my JS with ajax-request on another server it does not get reply from the server.

SOP (see above)
Was This Post Helpful? 0
  • +
  • -

#8 Asperant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 05-November 11

Re: ajax does not work on my hosting

Posted 25 March 2012 - 02:08 PM

View PostDormilich, on 25 March 2012 - 01:11 PM, said:

SOP (see above)



JS and PHP are on the same server:
Posted Image

1 - user from another server clicks the button (with onclick='captchaWork();')
2 - JS sends ajax-request to php-script
3 - php-script sends reply
4 - JS calls alert("reply");

This post has been edited by Asperant: 25 March 2012 - 02:12 PM

Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6062
  • View blog
  • Posts: 23,514
  • Joined: 23-August 08

Re: ajax does not work on my hosting

Posted 25 March 2012 - 03:11 PM

AFAIK, doesn't matter that it's the same server. Different domain.
Was This Post Helpful? 0
  • +
  • -

#10 Asperant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 05-November 11

Re: ajax does not work on my hosting

Posted 26 March 2012 - 07:40 AM

View PostJackOfAllTrades, on 25 March 2012 - 03:11 PM, said:

AFAIK, doesn't matter that it's the same server. Different domain.


OK, but, when I test it on my local computer - it works fine... Although, I use different domains on the local computer (one for the client and another one for the server).

And another thing - jQuery let us do crossdomain requests

So, what about my local machine? (the same server and different domains - so and hosting)
Was This Post Helpful? 0
  • +
  • -

#11 Asperant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 05-November 11

Re: ajax does not work on my hosting

Posted 26 March 2012 - 08:19 AM

I found:

If you want to do crossdomain ajax-requests, you should use jQuery:

$.getJSON("http://domain/script.php?callback=?", function(data){/*Server reply handling*/});


But - the example works only with GET method...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1