Sunday 15 March 2015

javascript - can't access php with ajax -


I have the problem that I can not access my php file with my $ .ajax () call. I always get a jqXHR.status of 0. This is my code: function: function updated with $ .ajax () call CliveInfo (text) {var data = text ; $ .ajax ({type: 'post', datatype: 'jason', url: '../.../php/updateInfo.php', data: {infoText: data, verb: "update"}, success: Work () {// warning ('success');}, error: function (jquxhr, exception) (if (jqXHR.status === 0) {warning ('not connected. \ N Verify the network.'); } And if (JqXHR.status == 404) {Warning ('The requested page was not found. [404]');} and if (jqXHR.status == 500) {Warning ('Internal server error [500].') ;} Other if (exception === 'parsererror') {Warning ('Requested JSON Par Failed. ');} And if (exception ===' timeout ') {Warning (' timeout error. ');} And if (exception ===' abort ') {Warning (' Ajax revoked request );} And {warnings ('Uncute error. \ N' + jqXHR.responseText);}}})}

I request this request to others in this project I have created, but this is the only one that does not work. I even want to access the PHP file:

php code snippet (updateInfo.php) :

  & lt;? PHP $ verb = $ _POST ['action']; $ Text = $ _POST ['data']; MyLog ($ action); MyLog ($ text); "Hello" echo; / * * Writes entry to logfile * / function myLog ($ data) {$ text = @file_get_contents ('log.txt'); $ Text = $ text "\ N". $ Data; @file_put_contents ('log.txt', $ text); }? & Gt;   

When I try to access this PHP file in the URI, there is echo output. So I think the problem should be in the AJAX call.

Do anyone have ideas that I am doing wrong?

You have a copy / paste error in the PHP file Should: $ action = $ _POST ['action']; $ Text = $ _POST ['infoText']; ['Data'] instead of $$ _POST

UPDATE

Because AJAX asks for JSON data requests, Just writing text in the file. Therefore, the AJAX request interprets the answer as zero, then the HTTP status = 0

resolve

the data type Not the kind of data you are sending to the server, but type the data coming back from the server or type the data: Type 'data' from 'jason', : 'html', Change or delete it to select the Simply JQuery mode to choose the appropriate mode.

No comments:

Post a Comment