0

I want to execute javascript for creating calendar using "calendarDateInput.js". Is it possible to execute javascript after an ajax call page using ajax tabs ?

I am not using any of the ajax libraries, only direct ajax call.

Here I want to call the function in an ajax returned page like DateInput("smsDate",true, "YYYY-MM-DD");

1
  • 1
    How are you making your Ajax call? I could give an example with jQuery... Commented Apr 1, 2011 at 17:42

3 Answers 3

2

Usually this is done by Callback functions. If you use libraries like jquery they usually provide hooks for callbacks.

check out jQuery.ajax() for doing the ajax call and then onsucess you can run additional javascript code...

http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.post/

var jqxhr = $.ajax({ url: "example.php" })
.success(function() { alert("success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });

I hope this is what you were asking for... otherwise please add some additional information to your question...

if you would not like to work with libraries like jquery ....

you have to check for the request status of you ajax call....

req = new XMLHttpRequest();

and then you have to check the response for following values

 // IF completed
if (req.readyState == 4) {

// Server HTTP Code if (req.status == 200) {

but jquery did all the work for you...

Sign up to request clarification or add additional context in comments.

2 Comments

There is any direct js instead of using Ajax libararies, since I am not using any libraries.
try jquery it's powerful and relative easy to start with... and you can go until super complex with it...
1

yes. for non jQuery:

var httpRequest = new XMLHttpRequest(); //your AJAX object
httpRequest.onreadystatechange = AJAXhandler; //your ajax handler function

function AJAXhandler() {
  if (httpRequest.readyState === 4) { //if success
    //process..
    //"YOU CAN CALL OTHER FUNCTIONS HERE"
  }
}

Comments

0

When using jQuery or normal javascript, callbacks are THE way things like this are handled. For example, using jQuery:

$.ajax({
   type: 'POST',
   url: 'PathTOMyUrl.html',
   success: function(data)
   {
       // This Callback will be invoked on successful call
   },
   error: function(data)
   {
       // This callback will be invoked on an error
   }
});

The callbacks can then contain code you find useful. In normal javascript, you would attach to the onreadystatechanged event on your AjaxRequest. You can find more information here.

1 Comment

The above snippet of code is javascript, just using jQuery. If you aren't using jQuery, you can find it here: http://jquery.com/

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.