2

im having a problem with getting any response from my server using Jquery and Ajax.

Server side:

$data = strtotime("now");
echo $data; // $data

Client side:

html code...
<script type="text/javascript" src=".../modjpicker2.js"></script>
</body>
</html>

modjpicker2.js:

$(function() {
 $.ajax({
        type: "GET",
        url: "ajaxtime",
        data: "{}",
        success: function(response) {
            var currentTime = new Date();
        }
    });
});

And var currentTime is just not being created... Some how request doesn't go through... Forgot to note that jQuery is working fine all scripts are attached in header and php is working good as well, link ajaxtime is live also.

5
  • If it doesn't get executed it means there was an error with your request, add the error method to your ajax to see what it is. Commented Mar 24, 2012 at 7:15
  • url:ajaxtime should be something like url:"yourdomain/ajaxtime.php", Commented Mar 24, 2012 at 7:17
  • Filename should be ajaxtime.php not ajaxtime. If you want to store the response in var currentTime, you have to give as var currentTime=response; Commented Mar 24, 2012 at 7:27
  • Sheikh Heera, nithi: ajaxtime is user friendly url, you can call it ajaxtime.php it doesn't change anything, and using the whole path doesn't change anything aswell. Commented Mar 24, 2012 at 15:38
  • slash197: would you please give a simplest example on how to use error method in my case? I'm not a pro with ajax yet. Commented Mar 24, 2012 at 15:39

2 Answers 2

1

In your html

<script type="text/javascript" src=".../modjpicker2.js"></script>

It should be

<script type="text/javascript" src="../modjpicker2.js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

"..." means there is a long address, there is no ... in address, modjpicker2.js works fine, the code provided is only part of the whole script, the second part works good.
0

I had kind of the same problem: My servers responses won't get handled by jQuery or JavaScript. It seems that nothing were transmitted.

I solved the issue by enabling HTTP access control on my server( More here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS)

Here's my solution:

jQuery client won't accept my server responses

Hope I can help! Let me know if it worked

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.