php - I am trying to perform a cross domain ajax request from a phonegap app and its not working -


i trying perform cross domain ajax request phonegap app , not working. trying submit form data database. have uploaded test domain using on server , works on mobile browser not when package phonegap. have looked on stackoverflow , can't find solution. help.

html:

<form id="uploadimage" method="post" action="" enctype="multipart/form-data" >     <label>name</label>     <input type="text" name="product_name" id="product_name" size="50"/>                                 <label>image</label>     <input type="file" id="image_file" name="image_file"/>     <input type="submit" class="button_style" value="add item"> </form> 

jquery:

$(document).ready(function() {     //detect deviceready event , call ondeviceready function         document.addeventlistener("deviceready", ondeviceready, false);     ondeviceready(); });  function ondeviceready(){     $("#uploadimage").submit(function(e) {         var file_data = $('#image_file').prop('files')[0];          var form = $('form')[0];               var form_data = new formdata(form);                               form_data.append('file', file_data);         //alert(form_data);                                          $.ajax({                     url: 'http://www.testdomain.com/iwp/form_app1/form_process.php', // point server-side php script                      datatype: 'text',  // expect php script, if                     cache: false,                     contenttype: false,                     processdata: false,                     data: form_data,                                              type: 'post',                     success: function(php_script_response){                             //alert(php_script_response); // display response php script, if                     },                 error: function(xhr, status, error) {                 alert("sarah" + xhr.responsetext);             }              });     }); } 

form_process.php

<?php header("access-control-allow-origin: *");  require("include/db_connect.php");     if(isset($_post["product_name"])){         //insert new item database after submitting add new item form          $product_name = $_post['product_name'];          $stmt_insert_item = $pdoconnection->prepare("insert test (testname) values (:testname)");         $stmt_insert_item->bindvalue(':testname', $product_name, pdo::param_str);           $stmt_insert_item->execute();          $pid = $pdoconnection->lastinsertid();         $pid_image = "id-" . $pid . ".jpg";         $image_directory = "images/" . $pid_image;          $stmt_update_item = $pdoconnection->prepare("update test set testimage=:testimage testid=:pid");         $stmt_update_item->bindvalue(':testimage', $image_directory, pdo::param_str);         $stmt_update_item->bindvalue(':pid', $pid, pdo::param_int);         $stmt_update_item->execute();          move_uploaded_file($_files['file']['tmp_name'], "" . $image_directory);      } ?> 

i have included following thought necessary cross domain requests in config.xml (for phonegap):

<feature name="http://api.phonegap.com/1.0/network"/>  <gap:plugin name="org.apache.cordova.device" /> <gap:plugin name="org.apache.cordova.network-information" /> <access origin="*" /> <plugin name="cordova-plugin-whitelist" version="1" /> <allow-intent href="http://*/*" /> <allow-intent href="https://*/*" /> 


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -