I have a ajax response, which contains 3 variable(a,b,c=array() ) in json Array,
i want to assign c to a php variable so that i can use it further.
Is it Possible if so then how can i do it?
I want to use this array of php to refresh a list In my View.
Asked
Active
Viewed 127 times
0

Vishal M
- 23
- 4
-
1php code processed on the server-side, but ajax is a client-side technology. So, to update a view via ajax requests you should use script which actually calls that requests. Also you definitely should provide some code for such questions. – Beloo Oct 07 '16 at 13:29
-
1Possible duplicate of [What is the difference between client-side and server-side programming?](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Heretic Monkey Oct 07 '16 at 16:17
1 Answers
3
By the time an AJAX call has returned a response to the browser, the PHP code has finished executing, so you will not be able to run any more PHP after this except by making another AJAX request.
If the html that makes up the list that you want to refresh is produced by a PHP view then you have two options.
1) Run the PHP code before your AJAX response is returned. That way your ajax response could be something like:
{"a":value,"b":value,"c":array,"d":"<ul>... updated list html code</ul>"}
You can then use JavaScript to replace the old HTML with your refreshed view stored in d.
2) You could store the value of c in a JavaScript variable where it can be re-used in a future AJAX request which will return the view HTML.
Hope this helps.

Andrew Van Duivenbode
- 141
- 4
-
Hi Andrew, Thanks for reply, I tried the same used my helper function to create html code so that i can output the same at View from ajax response, But as it contains many links and html code with strings with colon (:) in between , so it throwing error " SyntaxError: Unexpected token < in JSON " , is there any other way? , – Vishal M Oct 08 '16 at 13:49