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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Craig WagnerSoftware ArchitectCommented:
Yes it can, we do it all the time.

Open the JavaScript console in your browser or use Fiddler to look at the call to try to determine what is wrong.
WorknHardrAuthor Commented:
In some cases I have a partial view inside another partial view. I thought maybe the Ajax URL might need to be changed.
Miguel OzSoftware EngineerCommented:
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.
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

WorknHardrAuthor Commented:
I've found many solutions where adding / solved their issue like so:    
instead of:

I'm curious if this would work:
   var URL = document.location
Miguel OzSoftware EngineerCommented:
Yep, you just confirmed that the URL was the issue. The extra "/" at the start of the URL makes it a relative URL.
Regarding post question "URL/controller/action " will only work if it resolves in a valid location in your server. This is known as an absolute URL.
For more info about URLs check:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WorknHardrAuthor Commented:
Excellent, thx both...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.