通过jQuery Issue发布数据

时间:2014-11-26 23:52:21

标签: php jquery ajax

我没有得到使用此代码的响应,我正在尝试发布并返回一个值进行测试,但我无法修复它: 在php文件中,我只是使用<?php return "Post success"; ?>

有人可以帮我吗?

 $(document).ready(function() {
  $('#myForm').submit(function() {
    var url = "2534534534534";
    var u_image = "iVBORw0KGgoAAAANSUhEUgAAATYAAABOCAYAAACqujqxAAALgElEQVR4Xu2dT2wUVRzH6V9RiJCgwUQjxcR4KbSFRA9C7MWDMQY8+N8oisU/FzAh6oFIE29EpSRGCZBQEv9dRAh68EQRLx6AlnjzUjVEYowWgwRpKX6/09/bTKez7e7b2d3Zt99JJrs7O/Pe733ee9/5vX8zLYu0iYAIiEBgBFoCS4+SIwIiIAKLJGwqBCIgAsERkLAFl6VKkAiIgIRNZUAERCA4AhK24LJUCRIBEZCwqQyIgAgER0DCFlyWKkEiIAISNpUBERCB4AhI2ILLUiVIBERAwqYyIAIiEBwBCVtwWaoEiYAISNhUBkRABIIjIGELLkuVIBEQAQmbyoAIiEBwBCRswWWpEiQCIiBhUxkQAREIjoCELbgsVYJEQAQkbCoDIiACwRGQsAWXpUqQCIiAhE1lQAREIDgCErbgslQJEgERkLCpDIhAEQJ9fX0P8a9z586dEqTGIiBha6z8krU1INDb29vV2tq6u6WlZcuNGzcWnT17VvWkBtyzjEIZliVNhdXQBLq7u9d2dHS8DUF71iUEwvYHPLaVDZ0wD+Mp7kj7A7wUIn8R338ZHR0d9wiqLpdI2OqCXZHmjcD69es3o/J+TbsgbJF5oXtrEK9eJHMVhKsXaeb35dj743lDBo5H4vg4jkdCh3NG8H1ienp6NC8CKGHLWw2TPTUngL60/aiYrzpRQwW9gN+70AQdrrkxKRGuXbt2I8TnVth0eSF7ICyX4FmN8jzoFkVqCY4tbW9vX4zPLvzuQjj87KdopW1xYXdMnNAXiz8ufgh3Ar8pciNg+fPU1NRP2M4vZHuW/0vYsqSpsBqKACr+8ra2ttOogN2smPicQgIG6iVobP4h/h7zoCg89KToR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47zhSpzHlNUTEBxfuGlxbVm1czxSdiaOfcbOO0c0of5e7gmsNxkJEXNnghRbjBzzp9PKNMCLyaePDfpeSavTxNSeKF38Dw00y/6JgbxLkU4/8SfZ+YbVj2vk7DVk77irpiAvQyEb4SK3s+JrT8l0C4IQfx1b/N6axUblQggK+FMEbfMu4+S62id+Dqh5fsbwHICo9J8WEAuN5uofRh2blZTNJdZJKNqQYADE8l4sA51eUwsC3+jsnTheFeKXXwDejTtpB5bUpB8bHBh8CmNSEtrWhgprfcRnMdBnOidp/biGq7T5ObVf8nuBlx7J73HNO8Tx/keC3cjc2by5sV8KeSbTQ36JXP194Gra0QgNAJpwsk0FhPPWPr752MRWzYUvUl+ni7DkpCWGgbOu4oA3XPPZoVtAzmZ20LbSt2cDbjmP3iWiyVspZLTeSIQMAHzmDg3kP11FFd+p4c0q0mfhiClKVsyqdjKkUqF8RLs4ItdopUnEraSs0AnikDzEnDCZ6JHEM6zpAD2VMNzhFDN16c3YrnBqT2cvRM1i90mYWvesqqUi0BVCBRrhqdFVsrj3H2MlLD5UNM1IiACuSYgYct19sg4ERABHwJVFbaBgYFzaHsnh2h97NQ1IiACARHgVJGDBw/2VStJVRW2bdu2sUOvbvN8qgVN4YqACFRMYOzAgQNVc3qqKmwVJ10BiIAIiIAHAQmbBzRdIgIikG8CErZ854+sEwER8CAgYfOApktEQATyTUDClu/8kXUiIAIeBCRsHtB0iQiIQL4JSNjynT+yTgREwIOAhM0Dmi4RARHINwEJW77zR9aJgAh4EJCweUDTJSIgAvkmIGHLd/7IOhEQAQ8CEjYPaLpEBEQg3wQkbPnOH1knAiLgQUDC5gFNl4iACOSbgIQt3/kj60RABDwI/A8iEs4DwFSF7wAAAABJRU5ErkJggg==";    
    $.post('uploadSignature.php',
      {the_image : u_image,the_url : url},
      function(data){
        // show the response
        console.log(data);

      }).fail(function() {

        // just in case posting your form failed
        alert( "Posting failed." );

      });

      // to prevent refreshing the whole page page
      return false;

  });


});

3 个答案:

答案 0 :(得分:0)

return "Post success";,您不会发送任何内容(内容)。您必须将其更改为:

echo "Post success"; 

答案 1 :(得分:0)

是的,使用 echo 进行解决是一种选择。但我更喜欢将AJAX请求的返回结果作为JSON

你可以这样返回json

return json_encode(array('status'=>'OK','message'=>'Post success'));

解析之后
  function(data){
    var obj = jQuery.parseJSON(data);
    alert( obj.message );   //return Post success 
  })

使用JSON返回格式的原因是,您可以简单地处理更多错误及其原因。

答案 2 :(得分:0)

你不能在PHP文件中使用<?php return "Post success"; ?>,因为return是一个退出函数的关键字,可以在执行此操作时返回值。

执行您想要的操作的正确方法是<?php echo "Post success"; ?>,因为echo将其打印到DOM(文档),您也可以使用print。

另外,如果不在字符串中使用变量,只需快速注释使用单引号,<?php echo "Post success"; ?>效率低<?php echo 'Post success' ?>,因为PHP会用双引号搜索变量。