javascript - Ajax request returning whole page half the time -


I have found an HTML selection box in which the field selection of the random selection of 20 different code codes (i.e. "123456790") In the form, on-change trigger that is starting a regular Ajax post, which should set the text for a specific HTML element The code is as follows:

HTML

  & lt; Id = "mtn_select" name = "mtn_select" onChange = "setDetailValues ​​(this.value);" & Gt; & Lt; Option value = "0" selected & gt; Please select & lt; / Options & gt; By & lt;? Foreign currency ($ servicor $ serviceno => element $) {echo ' 

JS

  Function Set Dividivate Value (select_value) {if (select_value == 0) {$ ('# carcontrol'). Lesson (''); } {$ .ajax ({type: 'POST', url: 'module / ajax_mantence.php', data: {servicenumber: select_value}, datatype: 'text', success: function (return_data) {if (return_data) { Var myarr = return_data.split ("|"); $ ('# to get'); Text (myarr [1]);} and {$ ('# serve_city'). Text ('no data found');} }, Error: function (return_data) {$ ('# service_city'). Text ('an error occurred');}});  

PHP (AJAX_mantenation.php) with link-coded values ​​for now

   

Now it is not easy and works with purpose, but unfortunately still breaks like half time. When it works as a XHR-POST reaction (via firebug check), then "123456789 | New York | 22A in some places" will be expected and the city's price will be updated properly.

But in every other post response & lt ;! Whole HTML website code from DOCTYPE html public - - // w3c / DTD XHTML 1.0 Transcription // N "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional .dtd "> Too Last Line and Gt; When this happens, Ajax-Call does not recognize it as an error nor erase data, so the entire HTML code of the entire website will be within the "ReturnData" callback variable and printed on the website, where the value of the city is considered Appears.

The website has been integrated into this material quite Til (unknown to me) php- contains this, to use the GET parameter for the currently selected module (so indicate all the links index.php with different parameters) and the current user's session ID first I thought it There may be a problem (due to authentication / authorization content and SID) so I manually added the GET parameter to my AJAX-POST, but it did not change anything, I think Some servers must side and should be dealing with the season, but I really am very upset why this test / changes that advance which is not happening at all times and a loss.

The datatype value of your post request appears to be incorrect. To return JS formatted data to your PHP script Should modify and change Datatype to Jason.

Something like this for php:

  $ return_value = json_encode (array ($ service_nr, $ service bid, $ service_strict)); Echo $ return_value;  

Comments