$('#update-info').on('click',function() {
$.ajax({
url: '<?php echo Yii::$app->request->baseUrl . 'ajax'?>',
//data: {name: properties.filename},
type: "POST",
success: function () {
console.log("success");
},
error: function () {
console.log("failure");
}
});
});
Asked
Active
Viewed 1,194 times
0

Insane Skull
- 9,220
- 9
- 44
- 63

Ashutosh Parashar
- 85
- 2
- 12
-
google it, you will find your answer, if still d not get, then post your program here – Rajesh Pradhan Jun 14 '17 at 07:50
-
i cant find a specific answer or procedure to use that thats why i posted here – Ashutosh Parashar Jun 14 '17 at 07:53
-
if you show your code, then i can help you. – Rajesh Pradhan Jun 14 '17 at 07:55
-
you are using yii2 syntax in java script it wont work. give url like ?r=action_name/controller_name – Rajesh Pradhan Jun 14 '17 at 08:13
-
http://localhost:8080/site/ajax url which is being called – Ashutosh Parashar Jun 14 '17 at 08:16
-
this should call ajax $('#update-info').on('click',function() { $.ajax({ url: 'site/ajax', // data: {name: properties.filename}, type: "POST", success: function () { console.log("success"); }, error: function () { console.log("failure"); } }); }); – Rajesh Pradhan Jun 14 '17 at 08:19
-
I tried that it says 400 bad request – Ashutosh Parashar Jun 14 '17 at 08:22
-
this means you data section is having issue, can you check value of properties.filename – Rajesh Pradhan Jun 14 '17 at 08:26
-
it worked my csrf token was not false when i was making ajax request – Ashutosh Parashar Jun 14 '17 at 08:29
-
csrf token is something you should not disable. it compromise security – Rajesh Pradhan Jun 14 '17 at 08:31
-
if i pass this token in data filed? how can we pass it – Ashutosh Parashar Jun 14 '17 at 08:32
-
but the issue was with csrf token i just added beforeAction method in my controller which disabled csrf token value to false – Ashutosh Parashar Jun 14 '17 at 08:33
-
this csrf issue is solved here https://stackoverflow.com/questions/28473298/how-to-handle-csrf-validation-in-yii2-framework – Rajesh Pradhan Jun 14 '17 at 08:35
1 Answers
0
Use it as everywhere else:
$.ajax({
method: "POST",
url: "controller/action", // here your URL address
data: { name: "John", location: "Boston" }
});
Modify url
to match your address for ajax request.

Yupik
- 4,932
- 1
- 12
- 26
-
-
So the problem is propably in behaviors in controller. Update question with controller code. – Yupik Jun 14 '17 at 08:07
-
-