开发者

Jquery POST with same request not work

i have next problem

$("#btnsave").click(function () {
    $.post('svld.php', {
        'fnd': $('#fnd').attr("value")
    }, function (data) {
        alert(data);
    }, 'json');
}

slvd.php

header('Content-type: application/json');

    var_dump(json_encode($_POST));

in request i see next

fnd http://ya.ru

and have great response

string(24) "{"fnd":"http:\/\/y开发者_运维百科a.ru"}"

but alert(data) not runed

if i do same request on file parse.php in same folder

if($_POST['fnd']){

 header('Content-type: application/json');
 echo json_encode($cntTags->returnArrayTags());
}

all work perfect Have idea what it can be ?

header list

Date Thu, 08 Jul 2010 12:16:02 GMT
Server Apache/2.2.14 (Win32) PHP/5.3.0
X-Powered-By PHP/5.3.0
Content-Length 38
Keep-Alive timeout=5, max=99
Connection Keep-Alive
Content-Type application/json
Host localhost
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept application/json, text/javascript, */*
Accept-Language ru,en-us;q=0.7,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset windows-1251,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With XMLHttpRequest
Referer http://localhost/tz/
Content-Length 22
Cookie spylog_test=1


The issue is that your HTTP request is returning this string:

string(24) "{"fnd":"http:\/\/ya.ru"}"

What happens is that jQuery is trying to parse that but it fails because it's not a valid JSON string.

Try using echo instead of var_dump:

echo json_encode($_POST);

var_dump() outputs other information that you don't need, and that will screw up jQuery's JSON parsing.


Content-Type application/json Заголовки запросапоказать исходный код

looks alien to me. Looks like a character-set failure.

try

header('Content-type: application/json; charset=UTF-8');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜