javascript - Somewhat lost with jquery + php + json -
I'm starting to use jquery $ .ajax (), but I can not get back what I want I'll send it to:
$ (function () {$ .ajax ({url: "graph_data.php", type: "POST", data: "casi = 56 & nada = 48 & amp; Nuevo = 98 & amp; perfecto = 100 & amp; vales = 50 & apenas = 70 & amp; yes = 60 ", data type:" json ", error: work (xhr, Desc, exceptionobj) {document.writeln ("AL Error D XMLHTTPRequest Dice: + Xhr.responseText);}, Success: Function (JSN) {If (JSN. Terror) {Warning (Jason. Terror); Return;} var output= "" (P) in JSN {output = + P + ":" + Json [p] + "\ n";} document.writeln ("result: \ n \ n" + output);}}) ;}); And my PHP is:
& lt ;? php $ data = $ _POST ['data']; function array2json ($ Data) {$ json = $ data; return json_encode ($ json);}? & Gt; And when I execute it I come with them:
The result:
The same I used to have an echo array2json statement in php, but it just turned back to embezzlement ... I do not really know that What am i doing Is wrong and I get the same stuff as the only original for approximately 3 hours. Apart from this, I do not know how to get information from the web page in the $ .ajax function such as "data:" to pass parameters, can someone help me?
edit
I did what I did and prints this data now thank you very much =) However, I am thinking How could I send the data to "Data:" part in JQuery, so it tells it to the user's input, I was also checking the PP document and says that I have to write something:
< Pre> json_encode ($ a, JSON_HEX_TAG | JSON_HEX_APOS | however, if I do this then I get an error saying this It is that json_encode accepts 1 parameter and I am giving 2 ... no idea why? I am using php 5.2
First of all: the data you are sending to PHP scripts in $ _ POST , $ _ POST ['data'] No.
Next: You must actually call the array2json function with some data ... Is this a full code sample?
In addition, I'm not sure what to do array2json Do not ... why not call json_encode directly?
For your example, you can simply create your PHP file like this:
print json_encode ($ _ POST); Finally, you should find a tool to debug your AJAX calls easily. Edit :
In order to send the data to the user, you have to do just about anywhere in your page, then this and more data To catch or simply catch a different input field Then you can simply create your data query with it, which is very popular for JQuery as a string or object that makes it easy.
The reason you are getting an error is because the second argument was not added to PHP 5.3.0. So if you have anything in the past then it is not available to you.
Comments
Post a Comment