Answer the question
In order to leave comments, you need to log in
How to add Ajax to MVC?
How to send a POST request with Ajax if the URL is like this:
//mysite.ru/authorization/name/pupkin/pass/123
Is there a way to send such data?
And if not, how to make it understand such a URL: //mysite.ru/autorization?name=pupkin&pass=123
.htaccess is as follows:
RewriteEngine on
RewriteBase /
AddDefaultCharset utf-8
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Answer the question
In order to leave comments, you need to log in
How to send a POST request with Ajax if the URL is like this:
//mysite.ru/authorization/name/pupkin/pass/123
Apparently, you have problems with authorization. That's why people invented sessions. Log in once, for example, with Ajax like this:
$.post('http://example.com/auth', data: { pass: "qwerty", pass_confirmation: "qwerty" })
, something like this. The server creates a session for you, returns a cookie with this session. You keep it and continue to climb the pages, without the need for authorization on each. Let's take as an example the ExpressJS framework running on the NodeJS platform
, you can parse the URL in this way
app.get('/fruit/:fruitName/:fruitColor', function(req, res) {
var data = {
"fruit": {
"apple": req.params.fruitName,
"color": req.params.fruitColor
}
};
send.json(data);
});
.when('/pages/:pageName', {
templateUrl: 'views/single.html',
controller: 'singlePageController'
})
And why not (without going into the question of why you need such password manipulations, although this is interesting)?
First, what MVC are you using?
Normal MVC on the side, how many routes are there in the URL, it will parse and lay out everything for you as an array. And the parameters will come to the data post.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question