jquery - sending back json string with echo problem -


I use json_encode to return data via jquery from jquery via AJAX.

And I have noticed that Jquery only allows to use an echo in php.

If I use the echo json_encode ($ array); .... and then another echo json_encode ($ array2); In the same php file, then it will not work.

Or if I use the echo json_encode ($ array); And then another echo "Hello";

Am I right?

The problem is that when I use

  $ users = mysqli_fetch_assoc ($ login_user_result);  

The php file in AGX is called together

  with echo json_encode ($ array);  

It does not work, it correctly sends the $ array, but sends it along with the other code due to the above line.

But I have to use mysqli_fetch_assoc to get data from the database.

Is there work to do around this?

Edit: Here is the AJAX call I used:

  $ .ajax ({url: "static / js / ajaxcall_login.php" ("# login_box." "). Val ()}, datatype:" Jason ", success: function (data) {................})};  

I did not see anything wrong with your Ajax request.

Here is the test code and it works perfectly ...

Request :

  $ (Document) .ready (function () {$ .xx ({url: "json.php", type: "post", datatype: "jason", success: function (data) {alerts (data);}}) ;});  

Source :

  $ arr1 = array (3.14, 123, "foo"); $ Arr2 = array ("one", "two", "three"); $ Arr = array_merge ($ arr1, $ arr2); Echo json_encode ($ arr);  

Only one thing to note ...

If you type data on json in jQuery Ajax Request , Respnse (echo) should be worthy JSON. This is the reason why you can not echo out another string with JSON.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -