Link to home
Start Free TrialLog in
Avatar of WorknHardr
WorknHardr

asked on

Using Jquery AJAX in seperate Script File?

Since I moved my scripts from the MVC view into separate .js file, it cannot connect to another controller Action anymore.

Q. Can a AJAX work correctly in a separate .js file?
SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WorknHardr
WorknHardr

ASKER

In some cases I have a partial view inside another partial view. I thought maybe the Ajax URL might need to be changed.
The js file may be in a different location from where it was originally run, thus you need to change the URL parameter of your ajax call.
For example if you use jquery ajax, implement the error method and post the error message.  As stated previously by CraigWagner, Fiddler can help to capture  the call interaction and find the error.
I've found many solutions where adding / solved their issue like so:    
   /controller/action
or:
   /controller/action/
instead of:
   controller/action

I'm curious if this would work:
   var URL = document.location
   URL/controller/action
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent, thx both...